﻿# Empty scope
on_game_start = {
	events = {
		fp1_scandinavian_adventurers.0004	# FP1 - Organise Norse adventurers.
		fp1_scandinavian_adventurers.0011	# FP1 - Corral famous Norse adventurers that haven't done much yet.
		fp1_scandinavian_adventurers.0021	# FP1 - Mark game-start prioritised adventurers.
		#Guaranteed historical artifacts fixed spawning
		debug_portraits.1 					# Debug portraits for animation testing
		easteregg_event.0001				# Charna and Jakub duel.

		# Shogunate
		shogunate_alliance.0001				# Setup Alliances
		shogunate_bookmark.0004				# Setup Map Colors
		shogunate_bookmark.0003				# Setup Historical Periods
		shogunate_bookmark.0001				# Setup Historical Situation
		shogunate_nanbokucho.0001			# Setup Nanboku-cho Traits
		shogunate_nanbokucho.0009			# Setup Nanboku-cho Modifiers
		shogunate_startup.0001				# Setup Living Characters
		shogunate_startup.1000				# Setup Dead Characters
		shogunate_culture.0003				# Setup Arquebus
		shogunate_culture.0013				# Setup Cannon
		shogunate_target.0003				# Setup Global Coalitions
		shogunate_kamon.0001				# Setup Kamon CoA
	}

	effect = {
		#Epidemics 3 months grace
		set_global_variable = {
			name = start_epidemic_grace
			value = yes
			months = 3
		}
		#Set Cumania name if there is no MPO DLC
		if = {
			limit = {
				has_mpo_dlc_trigger = no
				current_date >= 1000.1.1
			}
			title:e_caspian-pontic_steppe = {
				set_title_name = cn_cumania
			}
		}
		#Rabbene Gershom outlaws polygamy
		if = {
			limit = {
				current_date >= 1000.1.1
			}
			religion:judaism_religion = {
				every_faith = {
					limit = {
						has_doctrine = temple_authority_rabbinic_doctrine
					}
					remove_doctrine = doctrine_polygamy
					add_doctrine = doctrine_monogamy
				}
			}
		}
		### 867 - RADHANITES IN KHAZARIA ###
		character:74025 = {
			if = {
				limit = {
					is_alive = yes
					is_playable_character = yes
				}
				trigger_event = bookmark.0200
			}
		}
		### 867 - WRATH OF THE NORTHMEN ###
		#Æthelred dying (probably)
		character:33358 = {
			if = {
				limit = {
					is_alive = yes
					is_playable_character = yes
				}
				trigger_event = {
					id = bookmark.0001
					days = { 365 730 }
				}
			}
		}

		#Alfred the Great becoming the Great
		character:7627 = {
			if = {
				limit = {
					is_alive = yes
					is_playable_character = yes
				}
				trigger_event = {
					id = bookmark.0002
					days = 1800 #~5 years
				}
			}
		}

		### 867 - THE GREAT ADVENTURERS ###
		character:251187 = {
			if = {
				limit = {
					is_alive = yes
					is_playable_character = yes
					AND = {
						character:251180 = { is_ai = yes }
						character:251181 = {
							is_ai = yes
							is_alive = yes
						}
					}
				}
				trigger_event = {
					id = bookmark.0101
					days = { 21 35 }
				}
			}
		}

		### 1066 - HASAN SABBAH STORY CYCLE ###
		character:41702 ?= {
			if = {
				limit = {
					is_alive = yes
					is_playable_character = yes
				}
				house = { set_house_head = prev }
				trigger_event = {
					id = hasan_sabbah.1000
					days = 1
				}
			}
		}
		### 1066 - EL CID STORY CYCLE ###
		character:107590 ?= {
			if = {
				limit = {
					cid_story_cycle_start_trigger = yes
				}
				trigger_event = {
					id = cid.0001
					days = 1
				}
			}
		}
		### 1066 - LOUIS THE GERMAN ###
		if = {
			limit = {
				exists = character:90107
				current_date >= 1066.1.1
			}
			character:90107 = { give_nickname = nick_the_german_post_mortem }
		}

		### 1178 - SIBYLLA ###
		if = {
			limit = {
				exists = character:223522
				current_date >= 1178.1.1
				AND = {
					character:223541 = {
						is_ai = yes
						is_alive = yes
					}
				}
			}
			character:223522 = {
				trigger_event = {
					id = bookmark.0300
					days = { 21 28 }
				}
			}
		}

		### HRE SETUP ###
		if = {
			limit = { exists = title:e_hre.holder }
			add_to_global_variable_list = {
				name = hre_elector_list
				target = title:c_cologne
			}
			add_to_global_variable_list = {
				name = hre_elector_list
				target = title:c_mainz
			}
			add_to_global_variable_list = {
				name = hre_elector_list
				target = title:c_trier
			}
			add_to_global_variable_list = {
				name = hre_elector_list
				target = title:d_bohemia
			}
			add_to_global_variable_list = {
				name = hre_elector_list
				target = title:d_east_franconia
			}
			add_to_global_variable_list = {
				name = hre_elector_list
				target = title:d_ostmark
			}
			add_to_global_variable_list = {
				name = hre_elector_list
				target = title:d_angria
			}
			hre_elector_list_save_effect = yes
			hre_margraves_effect = yes
		}

		### ARMENIAN SETUP ###
		title:e_byzantium.holder ?= {
			every_vassal = {
				limit = {
					government_has_flag = government_is_feudal
					vassal_contract_has_modifiable_obligations = yes
					faith = faith:armenian_apostolic
				}
				vassal_contract_set_obligation_level = { type = religious_rights level = 1 }
				set_subject_contract_modification_blocked = no
			}
		}
		title:e_arabia.holder ?= {
			every_vassal = {
				limit = {
					government_has_flag = government_is_feudal
					vassal_contract_has_modifiable_obligations = yes
					faith = faith:armenian_apostolic
				}
				vassal_contract_set_obligation_level = { type = feudal_government_taxes level = 3 }
				vassal_contract_set_obligation_level = { type = feudal_government_levies level = 2 }
				vassal_contract_set_obligation_level = { type = jizya_special_rights level = 1 }
				set_subject_contract_modification_blocked = no
			}
		}

		### CORONATION LOCATION SETUP ###
		if = {
			limit = {
				current_date >= 1066.1.1
				has_dlc_feature = coronations
			}
			# London (England)
			province:1527 = { 
				add_province_modifier = coronation_tradition_modifier 
				set_variable = {
					name = coronation_tradition_location
					value = 5
				}
			}
			# Aachen (Germany)
			province:2092 = { 
				add_province_modifier = coronation_tradition_modifier 
				set_variable = {
					name = coronation_tradition_location
					value = 5
				}
			}
			# Reims (France)
			province:2390 = { 
				add_province_modifier = coronation_tradition_modifier 
				set_variable = {
					name = coronation_tradition_location
					value = 5
				}
			}
			# Rome (Italy)
			province:2575 = { 
				add_province_modifier = coronation_tradition_modifier 
				set_variable = {
					name = coronation_tradition_location
					value = 5
				}
			}
			# Milan (Italy)
			province:2482 = { 
				add_province_modifier = coronation_tradition_modifier 
				set_variable = {
					name = coronation_tradition_location
					value = 5
				}
			}
			# Gniezno (Poland)
			province:4905 = { 
				add_province_modifier = coronation_tradition_modifier 
				set_variable = {
					name = coronation_tradition_location
					value = 5
				}
			}
			# Szekesfehervar (Hungary)
			province:3805 = { 
				add_province_modifier = coronation_tradition_modifier 
				set_variable = {
					name = coronation_tradition_location
					value = 5
				}
			}
			# Scone Abbey, Gowrie (Scotland)
			province:1741 = { 
				add_province_modifier = coronation_tradition_modifier 
				set_variable = {
					name = coronation_tradition_location
					value = 5
				}
			}
			# Byzantium (Byzantines)
			province:496 = { 
				add_province_modifier = coronation_long_tradition_modifier 
				set_variable = {
					name = coronation_tradition_location
					value = 10
				}
			}
			# Mahdiya (Africa)
			province:4578 = { 
				add_province_modifier = coronation_tradition_modifier 
				set_variable = {
					name = coronation_tradition_location
					value = 5
				}
			}
			# Cairo (Egypt)
			province:6042 = { 
				add_province_modifier = coronation_tradition_modifier 
				set_variable = {
					name = coronation_tradition_location
					value = 5
				}
			}
			# Damascus (Syria)
			province:5924 = { 
				add_province_modifier = coronation_tradition_modifier 
				set_variable = {
					name = coronation_tradition_location
					value = 5
				}
			}
			# Baghdad (Mesopotamia)
			province:4828 = { 
				add_province_modifier = coronation_long_tradition_modifier 
				set_variable = {
					name = coronation_tradition_location
					value = 10
				}
			}
			# Rayy (Persia)
			province:4319 = { 
				add_province_modifier = coronation_tradition_modifier 
				set_variable = {
					name = coronation_tradition_location
					value = 5
				}
			}
			# Ghazna (Kabulistan)
			province:4500 = { 
				add_province_modifier = coronation_tradition_modifier 
				set_variable = {
					name = coronation_tradition_location
					value = 5
				}
			}
			# Lahur (Punjab)
			province:1362 = { 
				add_province_modifier = coronation_tradition_modifier 
				set_variable = {
					name = coronation_tradition_location
					value = 5
				}
			}
			# Samarkand (Transoxiana)
			province:4404 = { 
				add_province_modifier = coronation_tradition_modifier 
				set_variable = {
					name = coronation_tradition_location
					value = 5
				}
			}
			# Bukhara (Transoxiana)
			province:4394 = { 
				add_province_modifier = coronation_tradition_modifier 
				set_variable = {
					name = coronation_tradition_location
					value = 5
				}
			}
			# Medina (Arabia)
			province:6212 = { 
				add_province_modifier = coronation_tradition_modifier 
				set_variable = {
					name = coronation_tradition_location
					value = 5
				}
			}
			# Kutaisi (Georgia)
			province:601 = { 
				add_province_modifier = coronation_tradition_modifier 
				set_variable = {
					name = coronation_tradition_location
					value = 5
				}
			}
		}
		if = {
			limit = {
				current_date >= 1178.1.1
				has_dlc_feature = coronations
			}
			# Marrakesh (Maghreb)
			province:4718 = { 
				add_province_modifier = coronation_tradition_modifier 
				set_variable = {
					name = coronation_tradition_location
					value = 5
				}
			}
			# Karakorum (Mongolia)
			province:1457 = { 
				add_province_modifier = coronation_tradition_modifier 
				set_variable = {
					name = coronation_tradition_location
					value = 5
				}
			}
		}

		### Every nomad and herder in the Steppe Region becomes tribal if DLC not enabled, pre-lobby history setup ###
		if = {
			limit = {
				has_mpo_dlc_trigger = no
			}
			# Change Nomad and Herder Holdings to Tribal Holdings for Tribals
			every_province = {
				limit = {
					OR = {
						has_holding_type = nomad_holding
						has_holding_type = herder_holding
					}
				}
				set_holding_type = tribal_holding
				if = {
					limit = {
						county.holder.capital_province ?= this
					}
					county.holder ?= {
						if = {
							limit = {
								NOT = {
									has_government = tribal_government
								}
							}
							change_government = tribal_government
						}
					}
				}
			}
		}

		setup_tributaries_effect = yes # defined in 00_tributary_setup_effect.txt

		### RELIGIOUS THINGS ###
		# Set up Holy Site Buildings to be buildable in Holy Sites
		religion:islam_religion = {
			every_faith = {
				every_holy_site = {
					limit = {
						title_province = {
							has_special_building_slot = no
							NOT = { this = province:235 }	# Higashinari (Osaka Castle)
						}
					}
					title_province = {
						add_special_building_slot = holy_site_mosque_01
					}
				}
			}
		}
		religion:christianity_religion = {
			every_faith = {
				every_holy_site = {
					limit = {
						title_province = {
							has_special_building_slot = no
							NOT = { this = province:235 }	# Higashinari (Osaka Castle)
						}
					}
					title_province = {
						add_special_building_slot = holy_site_cathedral_01
					}
				}
			}
		}
		religion:zoroastrianism_religion = {
			every_faith = {
				every_holy_site = {
					limit = {
						title_province = {
							has_special_building_slot = no
							NOT = { this = province:235 }	# Higashinari (Osaka Castle)
						}
					}
					title_province = {
						add_special_building_slot = holy_site_fire_temple_01
					}
				}
			}
		}
		every_religion_global = {
			limit = {
				OR = {
					this = religion:hinduism_religion
					this = religion:buddhism_religion
					this = religion:jainism_religion
					this = religion:tani_religion
					this = religion:bon_religion
				}
			}
			every_faith = {
				every_holy_site = {
					limit = {
						title_province = {
							has_special_building_slot = no
							NOT = { this = province:235 }	# Higashinari (Osaka Castle)
						}
					}
					title_province = {
						add_special_building_slot = holy_site_indian_grand_temple_01
					}
				}
			}
		}
		every_religion_global = {
			limit = {
				is_in_family = rf_pagan
			}
			every_faith = {
				every_holy_site = {
					limit = {
						title_province = {
							has_special_building_slot = no
							NOT = { this = province:235 }	# Higashinari (Osaka Castle)
						}
					}
					title_province = {
						add_special_building_slot = holy_site_pagan_grand_temple_01
					}
				}
			}
		}
		every_religion_global = {
			every_faith = {
				every_holy_site = {
					limit = {
						title_province = {
							has_special_building_slot = no
							NOT = { this = province:235 }	# Higashinari (Osaka Castle)
						}
					}
					title_province = {
						add_special_building_slot = holy_site_other_grand_temple_01
					}
				}
			}
		}

		# If your capital on game start is Mecca, you get the Hajjaj trait (since you can't Hajj to your capital)
		title:b_makka.county.holder = {
			if = {
				limit = {
					faith = { has_doctrine_parameter = mandatory_hajj }
					NOT = { has_trait = hajjaj }
				}
				# Have some Hajjaj
				add_trait = hajjaj
			}
		}

		# Pagans that start pre-reformed
		## Bon has already been reformed into new bon.
		faith:old_bon = {
			set_variable = { name = has_been_reformed }
		}

		# Mark some faiths to block conversion till specific decisions are taken.
		faith:basque_pagan = {
			set_variable = { name = block_conversion_till_decision_taken }
		}
		faith:adoptionist = {
			set_variable = { name = block_conversion_till_nebulous_circumstances }
		}
		# Kuzarite cannot be reformed under normal circumstances
		faith:kabarism = {
			set_variable = { name = block_reformation_var }
		}

		### GAME RULE: EXTRA ADMINS
		apply_historic_administrative_game_rule_effect = yes

		### 1178 CRUSADE SETUP ###
		if = {
			limit = {
				game_start_date >= 1178.10.1
			}
			religion:islam_religion = {
				set_variable = {
					name = variable_ghw_unlocked
					value = yes
				}
			}
			religion:christianity_religion = {
				set_variable = {
					name = variable_ghw_unlocked
					value = yes
				}
			}
			set_global_variable = {
				name = had_first_catholic_crusade
				value = yes
			}
		}
		if = {
			limit = {
				game_start_date >= 1178.10.1
			}
			character:st_amand_1 = {
				save_scope_as = leader
			}
			character:223523 = {
				save_scope_as = founder
			}
			title:b_saida = {
				save_scope_as = barony
			}
			create_holy_order_neutral_effect = {
				LEADER = scope:leader
				CAPITAL = scope:barony
				NEW_HO_SCOPE = new_holy_order
				FOUNDER = scope:founder
			}
		}
		if = {
			limit = {
				game_start_date >= 1178.10.1
			}
			character:231000 = {
				save_scope_as = leader_1
			}
			character:223523 = {
				save_scope_as = founder_1
			}
			title:b_hebron = {
				save_scope_as = barony_1
			}
			create_holy_order_neutral_effect = {
				LEADER = scope:leader_1
				CAPITAL = scope:barony_1
				NEW_HO_SCOPE = new_holy_order
				FOUNDER = scope:founder_1
			}
		}

		### UNIVERSITIES ###
		title:b_fes.title_province = { add_special_building_slot = generic_university }
		#title:b_bologna.title_province = { add_special_building_slot = generic_university } # Added in province history
		title:b_salamanca.title_province = { add_special_building_slot = generic_university }
		title:b_madrid.title_province = { add_special_building_slot = generic_university }
		#title:b_oxford.title_province = { add_special_building_slot = generic_university } # Added in province history
		title:b_cambridge.title_province = { add_special_building_slot = generic_university }
		title:b_padua.title_province = { add_special_building_slot = generic_university }
		title:b_coimbra.title_province = { add_special_building_slot = generic_university }
		title:b_napoli.title_province = { add_special_building_slot = generic_university }
		title:b_milano.title_province = { add_special_building_slot = generic_university }
		title:b_vienna.title_province = { add_special_building_slot = generic_university }
		title:b_praha.title_province = { add_special_building_slot = generic_university }
		title:b_perugia.title_province = { add_special_building_slot = generic_university }
		title:b_malappuram.title_province = { add_special_building_slot = generic_university }
		title:b_janakpur.title_province = { add_special_building_slot = generic_university }
		title:b_uppsala.title_province = { add_special_building_slot = generic_university }
		title:b_montlhery.title_province = { add_special_building_slot = generic_university } # Technically should be Paris, but that's occupied by Notre Dame
		title:b_qartajana.title_province = { add_special_building_slot = generic_university } # Technically should be Tunis, but that's occupied by a cathedral
		title:b_wazwan.title_province = { add_special_building_slot = generic_university } # Technically should be Isfahan, but that's occupied by the Friday Mosque
		title:b_sarsar.title_province = { add_special_building_slot = generic_university } # Technically should be Baghdad, but that's occupied by the House of Wisdom
		title:b_speyer.title_province = { add_special_building_slot = generic_university } # 1350ish, should be in Heidelberg but that's a church
		title:b_krakow.title_province = { add_special_building_slot = generic_university } # 1364
		title:b_pisa.title_province = { add_special_building_slot = generic_university } # 1350ish
		title:b_rostock.title_province = { add_special_building_slot = generic_university } # 1400ish
		title:b_turin.title_province = { add_special_building_slot = generic_university } # 1400ish
		title:b_ferrara.title_province = { add_special_building_slot = generic_university } # 1400ish
		title:b_leipzig.title_province = { add_special_building_slot = generic_university } # 1400ish, a city holding
		title:b_messina.title_province = { add_special_building_slot = generic_university }  # 1400ish, should be in Catania but that's a church
		if = {
			limit = {
				has_cp3_dlc_trigger = yes
			}
			title:b_sitges.title_province = { add_special_building_slot = generic_university } # Should be Barcelona but that location has another building now
		}
		else = {
			title:b_barcelona.title_province = { add_special_building_slot = generic_university } # 1450ish, but still fun to build
		}
		title:b_dumbarton.title_province = { add_special_building_slot = generic_university } # 1450ish, but still fun to build
		title:b_bidar.title_province = { add_special_building_slot = generic_university } # 1450ish, but still fun to build

		if = {
			limit = {
				has_cp3_dlc_trigger = yes
			}
	        title:b_barcelona.title_province = { add_special_building_slot = drassanes_01 } #1892
	        title:b_merv.title_province = { add_special_building = kyz_kala_01 } #4238
	        if = { limit = { game_start_date >= 1178.10.1 } title:b_cluny.title_province = { add_special_building = cluny_abbey_02 } } #2304
	        else_if = { limit = { game_start_date >= 1066.9.15 } title:b_cluny.title_province = { add_special_building = cluny_abbey_01 } }
	        else = { title:b_cluny.title_province = { add_special_building_slot = cluny_abbey_01 } }
	        title:b_york.title_province = { add_special_building = york_walls_01 } #1595
	        title:b_damascus.title_province = { add_special_building = damascus_mosque_01 } #5924
	        title:b_lhasa.title_province = { add_special_building = jokhang_01 } #9237
	        if = { limit = { game_start_date >= 1178.10.1 } title:b_schmalkalden.title_province = { add_special_building = wartburg_01 } } #3010
	        else = { title:b_schmalkalden.title_province = { add_special_building_slot = wartburg_01 } }
	        title:b_lalibela.title_province = { add_special_building_slot = beta_giyorgis_01 } #8301
	        if = { limit = { game_start_date >= 1066.9.15 } title:b_novgorod.title_province = { add_special_building = holy_wisdom_01 } } #5137
	        else = { title:b_novgorod.title_province = { add_special_building_slot = holy_wisdom_01 } }
	        title:b_kano.title_province = { add_special_building_slot = kano_walls_01 } #6519
	        #NOTE: b_somapur already has a special building
	        title:b_somapur.title_province = { remove_building = generic_university add_special_building = somapura_university_01 } #848
	        if = { limit = { game_start_date >= 1178.10.1 } title:b_firenze.title_province = { add_special_building = duomo_florence_02 } } #2543
	        else = { title:b_firenze.title_province = { add_special_building = duomo_florence_01 } }
	        title:b_konarak.title_province = { add_special_building_slot = konark_temple_01 } #928
	        title:b_fes.title_province = { add_special_building = al_qarawiyyin_university_01 } #4694
	        title:b_kairouan.title_province = { add_special_building = kairouan_basins_01 } #4594
	        title:b_al-ghaba.title_province = { add_special_building = ghana_palace_01 } #6628 #NOTE: likely existed since the 8th, but earliest (only) source on palace is from 1068
	        title:b_visegrad_hun.title_province = { add_special_building_slot = visegrad_castle_01 } #3803
	        if = { limit = { game_start_date >= 1161.9.15 } title:b_leczyca.title_province = { add_special_building = wawel_cathedral_01 } } #4924 #Date of consecreation of Archcollegiate Church of St. Mary and St. Alexius in Tum
	        else = { title:b_leczyca.title_province = { add_special_building_slot = wawel_cathedral_01 } }
	        title:b_vatapi.title_province = { add_special_building = vatapi_caves_01 } #1198
	        if = { limit = { game_start_date >= 1178.10.1 } title:b_jaisalmer.title_province = { add_special_building = jaisalmer_fort_01 } } #3387
	        else = { title:b_jaisalmer.title_province = { add_special_building_slot = jaisalmer_fort_01 } } #3387
		}

		### COA ###
		if = {
			limit = {
				game_start_date <= 1000.1.1
			}
			title:e_scandinavia = { set_coa = e_scandinavia_norse }
			title:k_sweden = { set_coa = k_sweden_norse }
			title:d_svealand = { set_coa = d_svealand_norse }
			title:c_upland = { set_coa = c_upland_norse }
			title:c_gastrikland = { set_coa = c_gastrikland_norse }
			title:c_sodermannaland = { set_coa = c_sodermannaland_norse }
			title:c_aland = { set_coa = c_aland_norse }
			title:d_bergslagen = { set_coa = d_bergslagen_norse }
			title:c_vastmanland = { set_coa = c_vastmanland_norse  }
			title:c_varmland = { set_coa = c_varmland_norse }
			title:c_dalarna = { set_coa = c_dalarna_norse }
			title:c_dalabergslagen = { set_coa = c_dalabergslagen_norse }
			title:d_vastergotland = { set_coa = d_vastergotland_norse }
			title:c_vastergotland = { set_coa = c_vastergotland_norse }
			title:c_skara = { set_coa = c_skara_norse }
			title:c_dal = { set_coa = c_dal_norse }
			title:c_nordmark = { set_coa = c_nordmark_norse }
			title:d_ostergotland = { set_coa = d_ostergotland_norse }
			title:c_ostergotland = { set_coa = c_ostergotland_norse }
			title:c_kinda = { set_coa = c_kinda_norse }
			title:c_narke = { set_coa = c_narke_norse }
			title:d_smaland = { set_coa = d_smaland_norse }
			title:c_more = { set_coa = c_more_norse }
			title:c_sevede = { set_coa = c_sevede_norse }
			title:c_varend = { set_coa = c_varend_norse }
			title:c_njudung = { set_coa = c_njudung_norse }
			title:c_finnveden = { set_coa = c_finnveden_norse }
			title:c_oland = { set_coa = c_oland_norse }
			title:d_norrland = { set_coa = d_norrland_norse }
			title:c_halsingland = { set_coa = c_halsingland_norse }
			title:c_medelpad = { set_coa = c_medelpad_norse }
			title:c_angermanland = { set_coa = c_angermanland_norse }
			title:d_gotland = { set_coa = d_gotland_norse }
			title:c_gutland = { set_coa = c_gutland_norse }
			title:k_norway = { set_coa = k_norway_norse }
			title:d_viken = { set_coa = d_viken_norse }
			title:c_vingulmork = { set_coa = c_vingulmork_norse }
			title:c_raniriki = { set_coa = c_raniriki_norse }
			title:c_vestfold = { set_coa = c_vestfold_norse }
			title:c_telemark = { set_coa = c_telemark_norse }
			title:d_agder = { set_coa = d_agder_norse }
			title:c_nedenes = { set_coa = c_nedenes_norse }
			title:c_agdeside = { set_coa = c_agdeside_norse }
			title:d_vestlandi = { set_coa = d_vestlandi_norse }
			title:c_rogalandi = { set_coa = c_rogalandi_norse }
			title:c_hordalandi = { set_coa = c_hordalandi_norse }
			title:c_sogn = { set_coa = c_sogn_norse }
			title:d_trandalog = { set_coa = d_trandalog_norse }
			title:c_trandheim = { set_coa = c_trandheim_norse }
			title:c_norwegian_more = { set_coa = c_norwegian_more_norse }
			title:c_firdafylki = { set_coa = c_firdafylki_norse }
			title:d_dalir = { set_coa = d_dalir_norse }
			title:c_hedmork = { set_coa = c_hedmork_norse }
			title:c_gudbrandsdalir = { set_coa = c_gudbrandsdalir_norse }
			title:c_eystridalir = { set_coa = c_eystridalir_norse }
			title:c_gauldala = { set_coa = c_gauldala_norse }
			title:d_halogaland = { set_coa = d_halogaland_norse }
			title:c_vastvag = { set_coa = c_vastvag_norse }
			title:c_bothin = { set_coa = c_bothin_norse }
			title:c_namdalfylki = { set_coa = c_namdalfylki_norse }
			title:d_iceland = { set_coa = d_iceland_norse }
			title:c_vestisland = { set_coa = c_vestisland_norse }
			title:c_nordrland = { set_coa = c_nordrland_norse }
			title:c_austisland = { set_coa = c_austisland_norse }
			title:c_sudurland = { set_coa = c_sudurland_norse }
			title:d_northern_isles = { set_coa = d_northern_isles_norse }
			title:c_orkney = { set_coa = c_orkney_norse }
			title:c_faereyar = { set_coa = c_faereyar_norse }
			title:c_shetland = { set_coa = c_shetland_norse }
			title:d_jamtland = { set_coa = d_jamtland_norse }
			title:c_jamtfir = { set_coa = c_jamtfir_norse }
			title:c_morarna = { set_coa = c_morarna_norse }
			title:c_helgum = { set_coa = c_helgum_norse }
			title:c_harjadalen = { set_coa = c_harjadalen_norse }
			title:k_denmark = { set_coa = k_denmark_norse }
			title:d_sjaelland = { set_coa = d_sjaelland_norse }
			title:c_sjaelland = { set_coa = c_sjaelland_norse }
			title:c_fyn = { set_coa = c_fyn_norse }
			title:c_lolland_falster = { set_coa = c_lolland_falster_norse }
			title:d_skane = { set_coa = d_skane_norse }
			title:c_skane = { set_coa = c_skane_norse }
			title:c_halland = { set_coa = c_halland_norse }
			title:c_bornholm = { set_coa = c_bornholm_norse }
			title:c_blekinge = { set_coa = c_blekinge_norse }
			title:d_jylland = { set_coa = d_jylland_norse }
			title:c_aarhus = { set_coa = c_aarhus_norse }
			title:c_viborg = { set_coa = c_viborg_norse }
			title:c_ringkobing = { set_coa = c_ringkobing_norse }
			title:c_aalborg = { set_coa = c_aalborg_norse }
			title:d_slesvig = { set_coa = d_slesvig_norse }
			title:c_slesvig = { set_coa = c_slesvig_norse }
			title:c_vorbasse = { set_coa = c_vorbasse_norse }
			title:c_ribe = { set_coa = c_ribe_norse }
			title:d_york = { set_coa = d_york_norse }
			title:c_east_riding = { set_coa = c_east_riding_norse }
			title:d_western_isles = { set_coa = d_western_isles_norse }
			title:c_inner_hebrides = { set_coa = c_inner_hebrides_norse  }
			title:c_dublin = { set_coa = c_dublin_norse }
			title:c_argyll = { set_coa = c_argyll_norse }
		}
		if = {
			limit = {
				game_start_date >= 1067.12.25
			}
			title:k_england = { set_coa = k_england_norman}
		}

		### GRANDEUR ###
		#Royal Court: Set starting Grandeur to be the same as Expected
		if = {
			limit = {
				has_dlc_feature = royal_court
			}
			every_character_with_royal_court = {
				set_current_court_grandeur = court_grandeur_minimum_expected
				apply_hold_court_grace_effect = yes
				# Stops Hold Court reminders at game start
				set_variable = {
					name = last_hold_court_date
					value = current_year
				}
			}
		}

		### STRUGGLES ###
		if = {
			limit = { current_date = 867.1.1 }

			# Iberian Struggle
			if = { # If we're in 867, Aragonese should be removed from the Struggle, since they don't quite exist yet.
				limit = { exists = struggle:iberian_struggle }
				struggle:iberian_struggle = { set_culture_as_uninvolved = culture:aragonese }
			}

			# Persian Struggle
			if = { # If the load order ever changes this struggle is going to break. This must always be read before the struggle.
				limit = { exists = struggle:persian_struggle }
				debug_log = "Samarra Struggle: Gamne start data has been set"
				struggle:persian_struggle = { # Use the object explorer to debug this data (yes, the time has come to learn how to use it)

					# Struggle on_start
					fp3_remove_vassal_contract_cooldown_for_tension_effect = yes

					# Flag some titles as un-dissolutionable within the struggle.
					title:e_arabia = { set_variable = struggle_block_dissolution_faction }
					title:d_sunni = { set_variable = struggle_block_dissolution_faction }
				}
			}
		}

		### REGENCIES ###
		# Pre-defined historic regencies setup.
		## NOTE: we do these first to avoid feed messages getting weird due to regents being replaced immediately after getting their position.
		## 867.
		### None. Yet.
		## 1066.
		if = {
			limit = { game_start_date = 1066.9.15 }
			# Designate some regents.
			## King Philippe of France & Duke Boudewijn of Flanders (friend of his dad's)
			character:214 = {
				designate_diarch = character:364
				# Baldwin of Flanders also promised the prior king he'd take care of Philippe, so we add that starting loyalty hook.
				add_hook = {
					type = predecessor_loyalty_hook
					target = character:364
					years = historic_regent_loyal_after_death_hook_duration_years_char_214_value
				}
			}
			### Plus remember who the promise was made to.
			character:364 = {
				add_opinion = {
					target = character:214
					modifier = promise_to_predecessor
					opinion = 50
				}
				set_variable = {
					name = promise_to_predecessor
					value = character:208
					years = historic_regent_loyal_after_death_hook_duration_years_char_214_value
				}
			}
			## Count Bouchard of Vendome & Guy de Bachaumont (his uncle)
			character:40905 = { designate_diarch = character:40376 }
			## Caliph al-Mustansir & Rasad (his mother)
			character:3096 = { designate_diarch = character:additional_fatimids_1 }
			## Count Ermengol of Urgell & Infanta Sancha of Aragon (his stepmother)
			character:110550 = { designate_diarch = character:110514 }
			## Duke Dirk of Holland & Count Robrecht of Zeeland (his stepfather)
			character:106520 = { designate_diarch = character:368 }
			## Duke Sven of Ostergotland & Kol Sverker (his father)
			character:100530 = { designate_diarch = character:100529 }
			## King Salamon of Hungary & Queen Mother Anastasia (his mother, in the absence of any better recorded options, and to keep other hostile relatives out of the job)
			character:476 = { designate_diarch = character:637 }
			## Prince Demetre of Georgia & Alda Oseti (his mother)
			character:9957 = { designate_diarch = character:9956 }
			## Sultan al-Muazzam Alp Arslan and Hassan "the Order of the Realm".
			character:3040 = {
				designate_diarch = character:3050
				# This is a vizierate as well, so start the diarchy manually.
				try_start_diarchy = vizierate
				# Tell Alp that he appointed Hassan so he remembers not to dismiss him.
				set_variable = {
					name = my_vizier
					value = character:3050
				}
			}
			## Constantine X & Michael Doukas.
			character:1732 = {
				if = {
					limit = { has_ep3_dlc_trigger = yes }
					try_start_diarchy = co_emperorship
					set_diarch = character:1736
					set_designated_heir = character:1736
				}
			}
			# Plus remove all the generated opinions.
			## King Philippe of France & Duke Boudewijn of Flanders
			remove_generated_diarch_consequences_effect = {
				NEW_DIARCH = character:364
				LIEGE = character:214
			}
			## Count Bouchard of Vendome & Guy de Bachaumont
			remove_generated_diarch_consequences_effect = {
				NEW_DIARCH = character:40376
				LIEGE = character:40905
			}
			## Caliph al-Mustansir & Rasad
			remove_generated_diarch_consequences_effect = {
				NEW_DIARCH = character:additional_fatimids_1
				LIEGE = character:3096
			}
			## Count Ermengol of Urgell & Infanta Sancha of Aragon
			remove_generated_diarch_consequences_effect = {
				NEW_DIARCH = character:110514
				LIEGE = character:110550
			}
			## Duke Dirk of Holland & Count Robrecht of Zeeland
			remove_generated_diarch_consequences_effect = {
				NEW_DIARCH = character:368
				LIEGE = character:106520
			}
			## Duke Sven of Ostergotland & Kol Sverker
			remove_generated_diarch_consequences_effect = {
				NEW_DIARCH = character:100529
				LIEGE = character:100530
			}
			## King Salamon of Hungary & Queen Mother Anastasia
			remove_generated_diarch_consequences_effect = {
				NEW_DIARCH = character:637
				LIEGE = character:476
			}
			## Prince Demetre of Georgia & Alda Oseti
			remove_generated_diarch_consequences_effect = {
				NEW_DIARCH = character:9956
				LIEGE = character:9957
			}
			## Sultan al-Muazzam Alp Arslan and Hassan "the Order of the Realm".
			remove_generated_diarch_consequences_effect = {
				NEW_DIARCH = character:3050
				LIEGE = character:3040
			}
		}
		if = {
			limit = { game_start_date = 1178.10.1 }
			# Set up some diarchs.
			## The future Richard I of England managing Aquitaine in place of his mother (who is under house arrest)
			character:205730 = { designate_diarch = character:204510 }
			## Jahan Pahlavan Muhammad as regent for Togrul
			character:144056 = { designate_diarch = character:144052 }
			## Manuel Komnenos and Alexios Komnenos
			character:215530 = {
				if = {
					limit = { has_ep3_dlc_trigger = yes }
					try_start_diarchy = junior_emperorship
					set_diarch = character:215531
					set_designated_heir = character:215531
				}
			}
			## Henry II of England and the Young King
			character:204500 = {
				designate_diarch = character:204508
				try_start_diarchy = co_monarchy
				set_designated_heir = character:204508
			}
			## Teresa of Portugal for Afonso the Conqueror
			character:209503 = {
				try_start_diarchy = regency
				set_diarch = character:209510
			}
			## Kara Khitai, Wolila for Zhilugu
			character:188912 = {
				try_start_diarchy = nomad_regency
				set_diarch = character:188909
			}
			# Plus remove all the generated opinions.
			## Richard I and Eleanor of Aquitaine
			remove_generated_diarch_consequences_effect = {
				NEW_DIARCH = character:204510
				LIEGE = character:205730
			}
			## Muhammad Jahan Pahlavan and Togrul
			remove_generated_diarch_consequences_effect = {
				NEW_DIARCH = character:144052
				LIEGE = character:144056
			}
			## Manuel Komnenos and Alexios
			remove_generated_diarch_consequences_effect = {
				NEW_DIARCH = character:215531
				LIEGE = character:215530
			}
			## Henry II and Young Henry
			remove_generated_diarch_consequences_effect = {
				NEW_DIARCH = character:204508
				LIEGE = character:204500
			}
			## Teresa and Afonso
			remove_generated_diarch_consequences_effect = {
				NEW_DIARCH = character:209510
				LIEGE = character:209503
			}
			## Wolila and Zhilugu 
			remove_generated_diarch_consequences_effect = {
				NEW_DIARCH = character:188909
				LIEGE = character:188912
			}

		}
		# Set up anyone who should be in a regency at start whether we have sources or not.
		## If you start as a child, incapable, or imprisoned, you get a regency.
		every_ruler = {
			if = {
				limit = {
					OR = {
						is_adult = no
						is_incapable = yes
						is_imprisoned = yes
					}
				}
				# We don't want to check over so many characters *twice*, so we check again inside the block to determine what type of regency to put 'em in.
				## Temporary Regencies.
				if = {
					limit = { is_imprisoned = yes }
					trigger_event = {
						id = diarchy.0001
						delayed = yes
					}
				}
				## Entrenched Regencies.
				else = {
					trigger_event = {
						id = diarchy.0011
						delayed = yes
					}
				}
			}
			if = {
				limit = {
					has_mpo_dlc_trigger = no
				}
				if = {
					limit = {
						has_government = nomad_government
					}
					change_government = tribal_government
				}
				else_if = {
					limit = {
						has_government = herder_government
					}
					change_government = tribal_government
				}
			}
		}
		# Sort custom regencies.
		## Fatimid Caliphate - basically stuck in the back-end of an entrenched regencies from game start.
		if = {
			limit = { exists = character:3096 }
			character:3096 = { trigger_event = diarchy.0012 }
		}
		else_if = {
			limit = { exists = character:188912 }
			character:188912 = { trigger_event = diarchy.0012 }
		}

		### FERTILE LANDS ###
		# For deserts that are supposed to be very fertile
		title:c_taizz = { add_county_modifier = fertile_desert_mountains_modifier }
		title:c_mandab = { add_county_modifier = fertile_desert_mountains_modifier }
		title:c_zabid = { add_county_modifier = fertile_desert_mountains_modifier }
		title:c_sanaa = { add_county_modifier = fertile_desert_mountains_modifier }
		title:c_dathina = { add_county_modifier = fertile_desert_mountains_modifier }

		### HENDEKAPOLIS ###
		title:c_ionia = { add_county_modifier = dodekapolis_modifier }
		title:c_chios = { add_county_modifier = dodekapolis_modifier }
		title:c_aeolis = { add_county_modifier = dodekapolis_modifier }
		title:c_lesbos = { add_county_modifier = dodekapolis_modifier }

		### GREECE BACKWATER COUNTIES ###
		if = {
			limit = { has_ep3_dlc_trigger = yes }
			title:c_laconia = { add_county_modifier = backwater_county_modifier }
			title:c_messenia = { add_county_modifier = backwater_county_modifier }
			title:c_korinthos = { add_county_modifier = backwater_county_modifier }
			title:c_achaia = { add_county_modifier = backwater_county_modifier }
			title:c_cephalonia = { add_county_modifier = backwater_county_modifier }
			title:c_attica = { add_county_modifier = backwater_county_modifier }
			title:c_boeotia = { add_county_modifier = backwater_county_modifier }
			title:c_aetolia = { add_county_modifier = backwater_county_modifier }
			title:c_naxos = { add_county_modifier = backwater_county_modifier }
			title:c_euboea = { add_county_modifier = backwater_county_modifier }
			title:c_neopatras = { add_county_modifier = backwater_county_modifier }
			title:c_demetrias = { add_county_modifier = backwater_county_modifier }
			title:c_thessaliotis = { add_county_modifier = backwater_county_modifier }
			title:c_thessalia = { add_county_modifier = backwater_county_modifier }
			title:c_epeiros = { add_county_modifier = backwater_county_modifier }
			title:c_buthrotum = { add_county_modifier = backwater_county_modifier }
			title:c_veria = { add_county_modifier = backwater_county_modifier }
			title:c_metzovo = { add_county_modifier = backwater_county_modifier }
			title:c_chalkidike = { add_county_modifier = backwater_county_modifier }
			title:c_thessalonika = { add_county_modifier = backwater_county_modifier }
			title:c_serres = { add_county_modifier = backwater_county_modifier }
			title:c_mosynopolis = { add_county_modifier = backwater_county_modifier }
			title:c_ohrid = { add_county_modifier = backwater_county_modifier }
			title:c_antipatreia = { add_county_modifier = backwater_county_modifier }
			title:c_dyrrachion = { add_county_modifier = backwater_county_modifier }
			title:c_avlonas = { add_county_modifier = backwater_county_modifier }
		}

		### Pandidakterion IN CONSTANTINOPLE ###
		if = {
			limit = {
				has_ep3_dlc_trigger = yes
				current_date >= 1046.1.1
			}
			title:c_byzantion = { add_county_modifier = pandidakterion_university_modifier }
		}

		### Varangian Guard ###
		if = {
			limit = {
				has_ep3_dlc_trigger = yes
				current_date >= 988.1.1
			}
			title:e_byzantium = { set_variable = founded_varangian_guard }
		}

		if = {
			limit = {
				has_dlc_feature = hybridize_culture
				NOT = {
					has_dlc_feature = khans_of_the_steppe
				}
			}
			culture:mongol = {
				add_culture_tradition = tradition_malleable_invaders
			}
			culture:khitan = {
				add_culture_tradition = tradition_malleable_invaders
			}
			culture:jurchen = {
				add_culture_tradition = tradition_malleable_invaders
			}
			culture:cuman = {
				add_culture_tradition = tradition_malleable_invaders
			}
			culture:bolghar = {
				add_culture_tradition = tradition_malleable_invaders
			}
			culture:bashkir = {
				add_culture_tradition = tradition_malleable_invaders
			}
			culture:karluk = {
				add_culture_tradition = tradition_malleable_invaders
			}
			culture:shatuo = {
				add_culture_tradition = tradition_malleable_invaders
			}
		}

		if = {
			limit = {
				NOT = {
					has_dlc_feature = khans_of_the_steppe
				}
			}
			culture:hunnic = { add_culture_tradition = tradition_horse_lords add_culture_tradition = tradition_steppe_tolerance }
			culture:saka = { add_culture_tradition = tradition_horse_lords }
			culture:alan = { add_culture_tradition = tradition_horse_lords add_culture_tradition = tradition_steppe_tolerance }
			culture:mongol = { add_culture_tradition = tradition_horse_lords add_culture_tradition = tradition_steppe_tolerance }
			culture:buryat = { add_culture_tradition = tradition_horse_lords add_culture_tradition = tradition_steppe_tolerance }
			culture:oirat = { add_culture_tradition = tradition_horse_lords }
			culture:naiman = { add_culture_tradition = tradition_horse_lords add_culture_tradition = tradition_steppe_tolerance }
			culture:kerait = { add_culture_tradition = tradition_horse_lords add_culture_tradition = tradition_steppe_tolerance }
			culture:khitan = { add_culture_tradition = tradition_horse_lords }
			culture:tuyuhun = { add_culture_tradition = tradition_horse_lords }
			culture:jurchen = { add_culture_tradition = tradition_horse_lords } 
			culture:cuman = { add_culture_tradition = tradition_horse_lords }
			culture:khazar = { add_culture_tradition = tradition_horse_lords add_culture_tradition = tradition_steppe_tolerance }
			culture:bolghar = { add_culture_tradition = tradition_horse_lords } 
			culture:bashkir = { add_culture_tradition = tradition_horse_lords } 
			culture:avar = { add_culture_tradition = tradition_horse_lords }
			culture:karluk = { add_culture_tradition = tradition_horse_lords add_culture_tradition = tradition_steppe_tolerance }
			culture:kimek = { add_culture_tradition = tradition_horse_lords }
			culture:kipchak = { add_culture_tradition = tradition_horse_lords } 
			culture:laktan = { add_culture_tradition = tradition_horse_lords }
			culture:kirghiz = { add_culture_tradition = tradition_horse_lords } 
			culture:yughur = { add_culture_tradition = tradition_horse_lords add_culture_tradition = tradition_steppe_tolerance }
			culture:uriankhai = { add_culture_tradition = tradition_horse_lords }
			culture:chuvash = { add_culture_tradition = tradition_horse_lords }
			culture:ongud = { add_culture_tradition = tradition_horse_lords }
			culture:turkmen = { add_culture_tradition = tradition_horse_lords }
			culture:mogyer = { add_culture_tradition = tradition_horse_lords }
			culture:pecheneg = { add_culture_tradition = tradition_horse_lords }
			culture:ongud = { add_culture_tradition = tradition_steppe_tolerance }
			culture:uyghur = { add_culture_tradition = tradition_steppe_tolerance }
			#culture:turkish = { add_culture_tradition = tradition_horse_lords }
		}

		### DEBUG GLOBAL VARIABLES ###
		# We set these here so that they present nicely and you can see when some variables register zero.

		# FP3 Struggle.
		if = {
			limit = { gather_debug_variables_for_persian_struggle_trigger = yes }
			# ENDING
			set_global_variable = {
				name = sp_end_date
				value = 0
			}
			# There's also fp3_struggle_ending; we don't track that here because it has functional usage that depends on it existing or not, so it's not a debug variable.

			# PHASES
			set_global_variable = {
				name = sp_phase_unrest
				value = 0
			}
			set_global_variable = {
				name = sp_phase_stabil
				value = 0
			}

			# UNREST
			set_global_variable = {
				name = sp_unrest_catalyst_yearly_influential_house_is_antagonistic_major
				value = 0
			}
			set_global_variable = {
				name = sp_unrest_catalyst_yearly_influential_house_is_antagonistic_medium
				value = 0
			}
			set_global_variable = {
				name = sp_unrest_catalyst_yearly_influential_house_is_antagonistic_minor
				value = 0
			}
			set_global_variable = {
				name = sp_unrest_catalyst_yearly_influential_house_is_antagonistic_minimal
				value = 0
			}
			set_global_variable = {
				name = sp_unrest_catalyst_becomes_rival_supporter_detractor
				value = 0
			}
			set_global_variable = {
				name = sp_unrest_catalyst_gain_claim_on_title_fp3
				value = 0
			}
			set_global_variable = {
				name = sp_unrest_catalyst_usurp_title_fp3
				value = 0
			}
			set_global_variable = {
				name = sp_unrest_catalyst_cadet_branch_created
				value = 0
			}
			set_global_variable = {
				name = sp_unrest_catalyst_supporter_forced_conversion
				value = 0
			}
			set_global_variable = {
				name = sp_unrest_catalyst_execute_supporter
				value = 0
			}
			set_global_variable = {
				name = sp_unrest_catalyst_imprison_supporter
				value = 0
			}
			set_global_variable = {
				name = sp_unrest_catalyst_unnatural_death_supporter
				value = 0
			}
			set_global_variable = {
				name = sp_unrest_catalyst_reveal_secret_supporter
				value = 0
			}
			set_global_variable = {
				name = sp_unrest_catalyst_turn_supporter_into_detractor
				value = 0
			}
			set_global_variable = {
				name = sp_unrest_catalyst_forming_alliance_between_detractor_uninvolved_rulers
				value = 0
			}
			set_global_variable = {
				name = sp_unrest_catalyst_detractor_win_unfair_war_within_the_region
				value = 0
			}
			set_global_variable = {
				name = sp_unrest_catalyst_detractor_win_fair_war_within_the_region
				value = 0
			}
			set_global_variable = {
				name = sp_unrest_catalyst_detractor_declare_unfair_war_within_the_region
				value = 0
			}
			set_global_variable = {
				name = sp_unrest_catalyst_detractor_declare_fair_war_within_the_region
				value = 0
			}
			set_global_variable = {
				name = sp_unrest_catalyst_became_detractor_fp3
				value = 0
			}
			# STABILISATION
			set_global_variable = {
				name = sp_stabil_catalyst_yearly_influential_house_is_harmonious_major
				value = 0
			}
			set_global_variable = {
				name = sp_stabil_catalyst_yearly_influential_house_is_harmonious_medium
				value = 0
			}
			set_global_variable = {
				name = sp_stabil_catalyst_yearly_influential_house_is_harmonious_minor
				value = 0
			}
			set_global_variable = {
				name = sp_stabil_catalyst_yearly_influential_house_is_harmonious_minimal
				value = 0
			}
			set_global_variable = {
				name = sp_stabil_catalyst_learned_new_language_important
				value = 0
			}
			set_global_variable = {
				name = sp_stabil_catalyst_vassalize_independent_ruler
				value = 0
			}
			set_global_variable = {
				name = sp_stabil_catalyst_invite_involved_as_honorary_guests_to_feast_hunt
				value = 0
			}
			set_global_variable = {
				name = sp_stabil_catalyst_supporter_win_unfair_war_within_the_region
				value = 0
			}
			set_global_variable = {
				name = sp_stabil_catalyst_supporter_win_fair_war_within_the_region
				value = 0
			}
			set_global_variable = {
				name = sp_stabil_catalyst_supporter_declare_unfair_war_within_the_region
				value = 0
			}
			set_global_variable = {
				name = sp_stabil_catalyst_supporter_declare_fair_war_within_the_region
				value = 0
			}
			set_global_variable = {
				name = sp_stabil_catalyst_install_loyalist_cb
				value = 0
			}
			set_global_variable = {
				name = sp_stabil_catalyst_imprison_detractor
				value = 0
			}
			set_global_variable = {
				name = sp_stabil_catalyst_execute_detractor
				value = 0
			}
			set_global_variable = {
				name = sp_stabil_catalyst_unnatural_death_detractor
				value = 0
			}
			set_global_variable = {
				name = sp_stabil_catalyst_reveal_secret_detractor
				value = 0
			}
			set_global_variable = {
				name = sp_stabil_catalyst_detractor_forced_conversion
				value = 0
			}
			set_global_variable = {
				name = sp_stabil_catalyst_turn_detractor_into_supporter
				value = 0
			}
			set_global_variable = {
				name = sp_stabil_catalyst_gain_struggle_titles_from_interlopers_uninvolved
				value = 0
			}
			set_global_variable = {
				name = sp_stabil_catalyst_became_supporter_fp3
				value = 0
			}
			# CONCESSION
			set_global_variable = {
				name = sp_concession_catalyst_missing_caliphate_or_arabian_empire
				value = 0
			}
			set_global_variable = {
				name = sp_concession_catalyst_caliph_or_emperor_loses_revolt_war
				value = 0
			}
			set_global_variable = {
				name = sp_concession_catalyst_caliph_or_emperor_accepts_faction_demands
				value = 0
			}
			set_global_variable = {
				name = sp_concession_catalyst_caliph_died_violently
				value = 0
			}
			set_global_variable = {
				name = sp_concession_catalyst_caliph_died_naturally
				value = 0
			}
			set_global_variable = {
				name = sp_concession_catalyst_war_ends_in_white_peace_between_supporter_detractor
				value = 0
			}
			set_global_variable = {
				name = sp_concession_catalyst_became_best_friend_soulmate_supporter_detractor
				value = 0
			}
			set_global_variable = {
				name = sp_concession_catalyst_became_friend_lover_supporter_detractor
				value = 0
			}
			set_global_variable = {
				name = sp_concession_catalyst_forming_alliance_between_supporter_detractor_rulers
				value = 0
			}
			set_global_variable = {
				name = sp_concession_catalyst_abandon_hook_on_supporter_detractor
				value = 0
			}
			set_global_variable = {
				name = sp_concession_catalyst_grants_pardon_supporter_detractor
				value = 0
			}
			set_global_variable = {
				name = sp_concession_catalyst_release_supporter_detractor
				value = 0
			}
			set_global_variable = {
				name = sp_concession_catalyst_ransom_supporter_detractor
				value = 0
			}
			set_global_variable = {
				name = sp_concession_catalyst_grants_vassal_to_de_jure_liege_supporter_detractor
				value = 0
			}
			set_global_variable = {
				name = sp_concession_catalyst_gift_supporter_detractor_ruler
				value = 0
			}
			set_global_variable = {
				name = sp_concession_catalyst_interloper_uninvolved_gain_struggle_titles
				value = 0
			}
			set_global_variable = {
				name = sp_concession_catalyst_raided_involved
				value = 0
			}
		}

		# UNITY CONFIG
		## 867.
		if = {
			limit = { game_start_date = 867.1.1 }
			# Twiddle some starting unities.
			## The Abassids are in the middle of a self-killing frenzy, so we lower theirs substantially.
			house:house_abbasid ?= {
				add_unity_value = {
					value = -100
					# This is from historical circumstances, so we just do use the house head.
					character = house_head
					desc = clan_unity_historical_circumstances.desc
				}
			}
			## The Samanids are juuuuust about to get started on killing each other over who gets to lead Transoxiana.
			house:house_samanid ?= {
				add_unity_value = {
					value = -40
					# This is from historical circumstances, so we just do use the house head.
					character = house_head
					desc = clan_unity_historical_circumstances.desc
				}
			}
			## The Afrighids (both of them) are having fairly few arguments because only one of them can speak and it's very easy to manage relations with a baby.
			dynasty:1042112.dynast.house ?= {
				add_unity_value = {
					value = 50
					# This is from historical circumstances, so we just do use the house head.
					character = house_head
					desc = clan_unity_historical_circumstances.desc
				}
			}
			## The Tahirids are scattered but actually get along quite well and support each other politically (mostly).
			dynasty:811.dynast.house ?= {
				add_unity_value = {
					value = 100
					# This is from historical circumstances, so we just do use the house head.
					character = house_head
					desc = clan_unity_historical_circumstances.desc
				}
			}
			## The Umayyads are having something of a renaissance.
			dynasty:597.dynast.house ?= {
				add_unity_value = {
					value = 100
					# This is from historical circumstances, so we just do use the house head.
					character = house_head
					desc = clan_unity_historical_circumstances.desc
				}
			}
		}
		# LEGITIMACY CONFIG
		## 867.
		if = {
			limit = { game_start_date = 867.1.1 }
			## Basileus Basileios was actually elected, so he's technically legitimate, but starts at level 2. With this he should be level 3.
			character:1700 = {
				add_legitimacy = major_legitimacy_gain
			}
		}

		# Cultural setup
		if = {
			limit = {
				game_start_date = 1178.10.1
			}
			culture:norman = {
				set_name_list = name_list_late_norman
			}
		}

		### EP3 BYZANTIUM IMPORTANT COUNTIES ###
		if = {
			limit = { has_ep3_dlc_trigger = yes }
			title:c_antiocheia = {
				set_important_location = {
					title = title:e_byzantium
					enter_realm_event = ep3_emperor_yearly.2000
				}
				set_important_location = {
					title = title:e_roman_empire
					enter_realm_event = ep3_emperor_yearly.2000
				}
			}
			title:c_jerusalem = {
				set_important_location = {
					title = title:e_byzantium
					enter_realm_event = ep3_emperor_yearly.2000
				}
				set_important_location = {
					title = title:e_roman_empire
					enter_realm_event = ep3_emperor_yearly.2000
				}
			}
			title:c_alexandria = {
				set_important_location = {
					title = title:e_byzantium
					enter_realm_event = ep3_emperor_yearly.2000
				}
				set_important_location = {
					title = title:e_roman_empire
					enter_realm_event = ep3_emperor_yearly.2000
				}
			}
			title:c_abbadan = {
				set_important_location = {
					title = title:e_byzantium
					enter_realm_event = ep3_emperor_yearly.2000
				}
				set_important_location = {
					title = title:e_roman_empire
					enter_realm_event = ep3_emperor_yearly.2000
				}
			}
			title:c_edessa = {
				set_important_location = {
					title = title:e_byzantium
					enter_realm_event = ep3_emperor_yearly.2000
				}
				set_important_location = {
					title = title:e_roman_empire
					enter_realm_event = ep3_emperor_yearly.2000
				}
			}
			title:c_bari = {
				set_important_location = {
					title = title:e_byzantium
					enter_realm_event = ep3_emperor_yearly.2000
				}
				set_important_location = {
					title = title:e_roman_empire
					enter_realm_event = ep3_emperor_yearly.2000
				}
			}
			title:c_siracusa = {
				set_important_location = {
					title = title:e_byzantium
					enter_realm_event = ep3_emperor_yearly.2000
				}
				set_important_location = {
					title = title:e_roman_empire
					enter_realm_event = ep3_emperor_yearly.2000
				}
			}
			title:c_roma = {
				set_important_location = {
					title = title:e_byzantium
					enter_realm_event = ep3_emperor_yearly.2000
				}
				set_important_location = {
					title = title:e_roman_empire
					enter_realm_event = ep3_emperor_yearly.2000
				}
			}
			title:c_ravenna = {
				set_important_location = {
					title = title:e_byzantium
					enter_realm_event = ep3_emperor_yearly.2000
				}
				set_important_location = {
					title = title:e_roman_empire
					enter_realm_event = ep3_emperor_yearly.2000
				}
			}
			title:c_tunis = {
				set_important_location = {
					title = title:e_byzantium
					enter_realm_event = ep3_emperor_yearly.2000
				}
				set_important_location = {
					title = title:e_roman_empire
					enter_realm_event = ep3_emperor_yearly.2000
				}
			}
			title:c_tangiers = {
				set_important_location = {
					title = title:e_byzantium
					enter_realm_event = ep3_emperor_yearly.2000
				}
				set_important_location = {
					title = title:e_roman_empire
					enter_realm_event = ep3_emperor_yearly.2000
				}
			}
			title:c_murcia = {
				set_important_location = {
					title = title:e_byzantium
					enter_realm_event = ep3_emperor_yearly.2000
				}
				set_important_location = {
					title = title:e_roman_empire
					enter_realm_event = ep3_emperor_yearly.2000
				}
			}
			title:c_lombardia = {
				set_important_location = {
					title = title:e_byzantium
					enter_realm_event = ep3_emperor_yearly.2000
				}
				set_important_location = {
					title = title:e_roman_empire
					enter_realm_event = ep3_emperor_yearly.2000
				}
			}
			title:c_trier = {
				set_important_location = {
					title = title:e_byzantium
					enter_realm_event = ep3_emperor_yearly.2000
				}
				set_important_location = {
					title = title:e_roman_empire
					enter_realm_event = ep3_emperor_yearly.2000
				}
			}
			title:c_cumberland = {
				set_important_location = {
					title = title:e_byzantium
					enter_realm_event = ep3_emperor_yearly.2000
				}
				set_important_location = {
					title = title:e_roman_empire
					enter_realm_event = ep3_emperor_yearly.2000
				}
			}
			title:c_northumberland = {
				set_important_location = {
					title = title:e_byzantium
					enter_realm_event = ep3_emperor_yearly.2000
				}
				set_important_location = {
					title = title:e_roman_empire
					enter_realm_event = ep3_emperor_yearly.2000
				}
			}
			title:c_chandax = {
				set_important_location = {
					title = title:e_byzantium
					enter_realm_event = ep3_emperor_yearly.2000
				}
				set_important_location = {
					title = title:e_roman_empire
					enter_realm_event = ep3_emperor_yearly.2000
				}
			}
			title:c_tourraine = {
				set_important_location = {
					title = title:e_byzantium
					enter_realm_event = ep3_emperor_yearly.2000
				}
				set_important_location = {
					title = title:e_roman_empire
					enter_realm_event = ep3_emperor_yearly.2000
				}
			}
			title:c_byzantion = {
				set_important_location = {
					title = title:e_byzantium
					enter_realm_event = roman_restoration.1200
				}
				set_important_location = {
					title = title:e_roman_empire
					enter_realm_event = roman_restoration.1200
				}
			}
		}

		# MPO Tribes of the North cultrad mechanic
		if = {
			limit = {
				has_dlc_feature = khans_of_the_steppe
			}
			every_county_in_region = {
				region = mpo_region_permafrost
				if = {
					limit = {
						holder.culture ?= culture
						culture = {
							has_cultural_parameter = permafrost_modifier_mechanic
						}
					}
					add_county_modifier = mpo_siberian_permafrost_modifier
				}
				else = {
					add_county_modifier = mpo_siberian_permafrost_modifier_bad
				}
				
			}
		}
		
		# Byzantine name game rule
		title:e_byzantium = {
			if = {
				limit = {
					has_game_rule = eastern_rome_name_of_byzantium
				}
				set_title_name = e_eastern_roman_empire
			}
			else_if = {
				limit = {
					has_game_rule = roman_empire_name_of_byzantium
				}
				set_title_name = e_roman_empire
			}
			else_if = {
				limit = {
					has_game_rule = romania_name_of_byzantium
				}
				set_title_name = e_romania_empire
			}
			else_if = {
				limit = {
					has_game_rule = empire_of_the_greeks_name_of_byzantium
				}
				set_title_name = e_empire_of_the_greeks
			}
			else_if = {
				limit = {
					has_game_rule = rhomaion_name_of_byzantium
				}
				set_title_name = e_rhomaion
			}
			else_if = {
				limit = {
					has_game_rule = unholy_roman_empire_name_of_byzantium
				}
				set_title_name = e_unholy_roman_empire
			}
		}

		# Admin - Let's give existing governors the Governor trait on game start
		every_independent_ruler = {
			limit = { government_allows = administrative }
			every_vassal = {
				limit = {
					is_governor = yes
					NOT = { has_trait = governor }
				}
				add_trait = governor
				add_trait_xp = {
					trait = governor
					value = {
						add = primary_title.title_held_years
						multiply = 2
					}
				}
			}
		}

		# Remove Coronation Doctrine if you don't have the DLC
		if = {
			limit = {
				has_ach_dlc_trigger = no
			}
			every_religion_global = {
				every_faith = {
					switch = {
						trigger = has_doctrine
						doctrine_no_anointment = { remove_doctrine = doctrine_no_anointment }
						doctrine_anointment_permitted = { remove_doctrine = doctrine_anointment_permitted }
						doctrine_imperial_anointment = { remove_doctrine = doctrine_imperial_anointment }
					}
				}
			}
		}

		# Set Coronation laws for everyone
		if = {
			limit = {
				has_ach_dlc_trigger = yes
			}
			every_ruler = {
				limit = {
					coronation_trigger = yes
					age >= 12
					NOT = { this = character:1316 } # Heinrich IV was coronated in 1084
				}
				save_temporary_scope_as = ruler
				if = {
					limit = {
						highest_held_title_tier > tier_kingdom
						NOT = {
							has_any_shunned_or_criminal_trait_in_faith_trigger = {
								CHARACTER = scope:ruler
								FAITH = scope:ruler.faith
							}
							faith = { has_doctrine = doctrine_no_anointment }
						}	
					}
					if = {
						limit = {
							NOT = {
								has_game_rule = coronation_laws_off
							}
						}
						add_realm_law_skip_effects = crowned_emperor
					}
					set_variable = crowned_emperor_var
				}
				else = {
					if = {
						limit = {
							NOT = {
								has_game_rule = coronation_laws_off
							}
						}
						add_realm_law_skip_effects = crowned_king
					}
					set_variable = crowned_king_var
				}
			}
		}
		
		if = {
			limit = {
				title:k_magyar = {
					exists = holder
				}
			}
			title:k_magyar = {
				add_title_law = confederation_elective_succession_law
			}
		}
	}
}

# Like on_game_start, except it is called once the host (or player, in single player) exits the lobby. Good for anything where you need to know who the players are, or what the game rules are
on_game_start_after_lobby = {
	effect = {
		# To prevent the Season Changes event from triggering on game start
		situation:the_great_steppe ?= {
			every_participant_group = {
				every_situation_group_participant = {
					set_variable = {
						name = steppe_game_start_var
						years = 1
					}
				}
			}
		}

		# Extra Nomad Regions
		#Tibet
		if = {
		    limit = {
				has_mpo_dlc_trigger = yes
				has_game_rule = tibet_nomad_region_on
			}
			start_situation = {
				type = game_rule_extra_nomads_tibet
				start_phase = situation_steppe_abundant_grazing_season
				save_scope_as = my_situation
			}
			scope:my_situation = {
				every_situation_county = {
					limit = {
						holder = {
							government_has_flag = government_is_tribal
						}
					}
					holder = {
						set_variable = {
							name = steppe_game_start_var
							years = 1
						}
						every_held_title = {
							if = {
								limit = {
									title_province = {
										has_holding_type = tribal_holding
									}
								}
								title_province = {
									set_holding_type = nomad_holding
								}
							}
						}
						change_government = nomad_government
						if = {
							limit = {
								OR = {
									domicile.domicile_culture != capital_county.culture
									domicile.domicile_faith != capital_county.faith
								}
							}
							domicile = {
								set_domicile_culture = prev.capital_county.culture
								set_domicile_faith = prev.capital_county.faith
							}
						}
					}
				}
			}
			title:k_xia ?= {
				every_in_de_jure_hierarchy = {
					limit = {
						holder ?= {
							government_has_flag = government_is_tribal
						}
					}
					holder = {
						set_variable = {
							name = steppe_game_start_var
							years = 1
						}
						every_held_title = {
							if = {
								limit = {
									title_province = {
										has_holding_type = tribal_holding
									}
								}
								title_province = {
									set_holding_type = nomad_holding
								}
							}
						}
						change_government = nomad_government
					}
				}
			}
		}
		#Sami
		if = {
		    limit = {
				has_mpo_dlc_trigger = yes
				has_game_rule = sami_nomad_region_on
			}
			start_situation = {
				type = game_rule_extra_nomads_sami
				start_phase = situation_steppe_abundant_grazing_season
				save_scope_as = my_situation
			}
			scope:my_situation = {
				every_situation_county = {
					limit = {
						holder = {
							OR = {
								culture = culture:sami
								culture = culture:karelian
								culture = culture:samoyed
								is_ai = no
							}
						}
					}
					holder = {
						set_variable = {
							name = steppe_game_start_var
							years = 1
						}
						every_held_title = {
							if = {
								limit = {
									title_province = {
										has_holding_type = tribal_holding
									}
								}
								title_province = {
									set_holding_type = nomad_holding
								}
							}
						}
						change_government = nomad_government
					}
				}
			}
		}
		#Arabia
		if = {
		    limit = {
				has_mpo_dlc_trigger = yes
				has_game_rule = arabia_nomad_region_on
			}
			start_situation = {
				type = game_rule_extra_nomads_arabs
				start_phase = situation_steppe_severe_drought_season
				save_scope_as = my_situation
				sub_region = {
					key = arabia_nomads
					start_phase = situation_steppe_severe_drought_season
					map_color = { 34 255 76 }
					geographical_regions = { arab_nomad_area }
				}
				sub_region = {
					key = egypt_nomads
					start_phase = situation_steppe_abundant_grazing_season
					map_color = { 24 155 76 }
					geographical_regions = { egypt_nomad_area }
				}
			}
			scope:my_situation = {
				every_situation_county = {
					limit = {
						holder = {
							government_has_flag = government_is_tribal
						}
					}
					holder = {
						set_variable = {
							name = steppe_game_start_var
							years = 1
						}
						every_held_title = {
							if = {
								limit = {
									title_province = {
										has_holding_type = tribal_holding
									}
								}
								title_province = {
									set_holding_type = nomad_holding
								}
							}
						}
						change_government = nomad_government
					}
				}
			}
		}
		#Sahel
		if = {
		    limit = {
				has_mpo_dlc_trigger = yes
				has_game_rule = sahel_nomad_region_on
			}
		    start_situation = { 
				type = game_rule_extra_nomads_sahel
				start_phase = situation_steppe_severe_drought_season
				save_scope_as = my_situation
				sub_region = {
					key = north_africa_nomads
					start_phase = situation_steppe_abundant_grazing_season
					map_color = { 155 62 0 }
					geographical_regions = { sahel_north_africa_nomad_area }
				}
				sub_region = {
					key = sahara_nomads
					start_phase = situation_steppe_severe_drought_season
					map_color = { 255 232 100 }
					geographical_regions = { sahel_desert_nomad_area }
				}
				sub_region = {
					key = sahel_nomads
					start_phase = situation_steppe_abundant_grazing_season
					map_color = { 100 46 92 }
					geographical_regions = { sahel_sub_saharan_africa_nomad_area }
				}
			}
			scope:my_situation = {
				every_situation_county = {
					limit = {
						holder = {
							government_has_flag = government_is_tribal
							OR = {
								culture = { has_cultural_pillar = heritage_berber }
								culture = culture:bedouin
								is_ai = no
							}
						}
					}
					holder = {
						set_variable = {
							name = steppe_game_start_var
							years = 1
						}
						every_held_title = {
							if = {
								limit = {
									title_province = {
										has_holding_type = tribal_holding
									}
								}
								title_province = {
									set_holding_type = nomad_holding
								}
							}
						}
						change_government = nomad_government
					}
				}
			}
		}	
		#Horn of Africa
		if = {
		    limit = {
				has_mpo_dlc_trigger = yes
				has_game_rule = horn_of_africa_nomad_region_on
			}
		    start_situation = { 
				type = game_rule_extra_nomads_horn
				start_phase = situation_steppe_severe_drought_season
				save_scope_as = my_situation
			}
			scope:my_situation = {
				every_situation_county = {
					limit = {
						holder = {
							government_has_flag = government_is_tribal
							OR = {
								culture = culture:somali
								culture = culture:beja
								culture = culture:afar
								culture = culture:bedouin
								AND = {
									is_ai = no
									NOR = {
										culture = culture:welayta
										culture = culture:ethiopian
										culture = culture:nubian
										culture = culture:daju
									}
								}
							}
						}
					}
					holder = {
						set_variable = {
							name = steppe_game_start_var
							years = 1
						}
						every_held_title = {
							if = {
								limit = {
									title_province = {
										has_holding_type = tribal_holding
									}
								}
								title_province = {
									set_holding_type = nomad_holding
								}
							}
						}
						change_government = nomad_government
					}
				}
			}
		}	
		every_ruler = {
			### Every nomad in the Steppe Region gets their yurt domicile goodies ###
			if = {
				limit = {
					government_has_flag = government_is_nomadic
					is_landed = yes
				}
				save_scope_as = holder
				if = {
					limit = {
						NOT = {
							any_held_title = {
								is_nomad_title = yes
							}
						}
					}
					create_nomad_title = {
						name = nomad_title_name
						holder = scope:holder
						government = nomad_government
						save_scope_as = new_nomad_title
					}
				}
				if = {
					limit = {
						exists = situation:the_great_steppe
						any_character_situation = {
							this = situation:the_great_steppe
						}
					}
					add_trait = nomadic_philosophy
					dynasty ?= {
						every_dynasty_member = {
							limit = {
								top_liege ?= {
									government_has_flag = government_is_nomadic
								}
							}
							add_trait = nomadic_philosophy
						}
					}
				}
				switch = {
					trigger = primary_title.tier
					tier_county = {
						add_gold = {
							value = {
								value = 0
								add = { 25 40 }
								multiply = gold_value_scale_by_era
							}
						}
					}
					tier_duchy = {
						add_gold = {
							value = {
								value = 0
								add = { 50 80 }
								multiply = gold_value_scale_by_era
							}
						}
						add_realm_law_skip_effects = nomadic_authority_2
						domicile ?= {
							add_domicile_building = yurt_main_02
							add_random_yurt_external_building_effect = yes
							add_random_yurt_external_building_effect = yes
							upgrade_random_yurt_external_building_effect = yes
						}
					}
					tier_kingdom = {
						add_gold = {
							value = {
								value = 0
								add = { 100 125 }
								multiply = gold_value_scale_by_era
							}
						}
						add_realm_law_skip_effects = nomadic_authority_3
						domicile ?= {
							add_domicile_building = yurt_main_02
							add_domicile_building = yurt_main_03
							add_random_yurt_external_building_effect = yes
							add_random_yurt_external_building_effect = yes
							upgrade_random_yurt_external_building_effect = yes
							upgrade_random_yurt_external_building_effect = yes
						}
					}
					tier_empire = {
						add_gold = {
							value = {
								value = 0
								add = { 150 200 }
								multiply = gold_value_scale_by_era
							}
						}
						add_realm_law_skip_effects = nomadic_authority_3
						domicile ?= {
							add_domicile_building = yurt_main_02
							add_domicile_building = yurt_main_03
							add_domicile_building = yurt_main_04
							add_random_yurt_external_building_effect = yes
							add_random_yurt_external_building_effect = yes
							add_random_yurt_external_building_effect = yes
							upgrade_random_yurt_external_building_effect = yes
							upgrade_random_yurt_external_building_effect = yes
							upgrade_random_yurt_external_building_effect = yes
							upgrade_random_yurt_external_building_effect = yes
							upgrade_random_yurt_external_building_effect = yes
							upgrade_random_yurt_external_building_effect = yes
							upgrade_random_yurt_external_building_effect = yes
							upgrade_random_yurt_external_building_effect = yes
						}
					}
				}
				if = {
					limit = {
						has_royal_court = yes
						NOT = { has_court_type = court_nomadic }
					}
					set_court_type = court_nomadic
				}
				every_councillor = {
					limit = {
						NOR = {
							has_council_position = councillor_spymaster
							has_council_position = councillor_court_chaplain
							has_council_position = councillor_spouse
						}
					}
					prev = { fire_councillor_skip_effects = prev }
					remove_opinion = {
						modifier = fired_from_council_opinion
						target = prev
					}
				}
				random_courtier = {
					limit = {
						is_adult = yes
					}
					save_scope_as = astrologer_character
					prev = {
						appoint_court_position = {
							recipient = scope:astrologer_character
							court_position = court_astrologer_court_position
						}
					}
				}
				if = {
					limit = {
						OR = {
							NOT = { exists = cp:councillor_kurultai_1 }
							NOT = { exists = cp:councillor_kurultai_2 }
							NOT = { exists = cp:councillor_kurultai_3 }
							NOT = { exists = cp:councillor_kurultai_4 }
						}
					}
					ordered_vassal = {
						order_by = current_military_strength
						limit = {
							is_councillor = no
						}
						make_councillor_start_up_effect = yes
					}
				}
				if = {
					limit = {
						OR = {
							NOT = { exists = cp:councillor_kurultai_1 }
							NOT = { exists = cp:councillor_kurultai_2 }
							NOT = { exists = cp:councillor_kurultai_3 }
							NOT = { exists = cp:councillor_kurultai_4 }
						}
					}
					every_knight = {
						limit = {
							is_councillor = no
						}
						make_councillor_start_up_effect = yes
					}
				}
				ordered_councillor = {
					order_by = stewardship
					position = 0
					limit = {
						NOR = {
							has_council_position = councillor_spymaster
							has_council_position = councillor_court_chaplain
							has_council_position = councillor_spouse
						}
					}
					switch = {
						trigger = this
						liege_or_court_owner.cp:councillor_kurultai_1 = {
							set_council_task = {
								task_type = task_kurultai_fertility_1
								target = liege_or_court_owner.capital_province
							}
						}
						liege_or_court_owner.cp:councillor_kurultai_2 = {
							set_council_task = {
								task_type = task_kurultai_fertility_2
								target = liege_or_court_owner.capital_province
							}
						}
						liege_or_court_owner.cp:councillor_kurultai_3 = {
							set_council_task = {
								task_type = task_kurultai_fertility_3
								target = liege_or_court_owner.capital_province
							}
						}
						liege_or_court_owner.cp:councillor_kurultai_4 = {
							set_council_task = {
								task_type = task_kurultai_fertility_4
								target = liege_or_court_owner.capital_province
							}
						}
					}
				}
				ordered_councillor = {
					order_by = learning
					position = 0
					limit = {
						NOR = {
							has_council_position = councillor_spymaster
							has_council_position = councillor_court_chaplain
							has_council_position = councillor_spouse
							is_performing_council_task = task_kurultai_fertility_1
							is_performing_council_task = task_kurultai_fertility_2
							is_performing_council_task = task_kurultai_fertility_3
							is_performing_council_task = task_kurultai_fertility_4
						}
					}
					switch = {
						trigger = this
						liege_or_court_owner.cp:councillor_kurultai_1 = {
							set_council_task = {
								task_type = task_kurultai_court_astrologer_1
								target = liege_or_court_owner.capital_province
							}
						}
						liege_or_court_owner.cp:councillor_kurultai_2 = {
							set_council_task = {
								task_type = task_kurultai_court_astrologer_2
								target = liege_or_court_owner.capital_province
							}
						}
						liege_or_court_owner.cp:councillor_kurultai_3 = {
							set_council_task = {
								task_type = task_kurultai_court_astrologer_3
								target = liege_or_court_owner.capital_province
							}
						}
						liege_or_court_owner.cp:councillor_kurultai_4 = {
							set_council_task = {
								task_type = task_kurultai_court_astrologer_4
								target = liege_or_court_owner.capital_province
							}
						}
					}
				}
				#Nomadic Philosophy lobby added realms
				if = {
					limit = {
						exists = situation:the_great_steppe
						any_character_situation = {
							this = situation:the_great_steppe
						}
						NOT = {
							has_trait = nomadic_philosophy
						}
					}
					add_trait = nomadic_philosophy
					dynasty ?= {
						every_dynasty_member = {
							limit = {
								top_liege ?= {
									government_has_flag = government_is_nomadic
								}
							}
							add_trait = nomadic_philosophy
						}
					}
				}
			}
			else_if = {
				limit = {
					government_has_flag = government_is_herder
				}
				if = {
					limit = { gold >= 30 }
					remove_short_term_gold = 27
				}
				else_if = {
					limit = { gold >= 25 }
					remove_short_term_gold = 22
				}
				else_if = {
					limit = { gold >= 20 }
					remove_short_term_gold = 18
				}
				else_if = {
					limit = { gold >= 15 }
					remove_short_term_gold = 11
				}
				else_if = {
					limit = { gold >= 10 }
					remove_short_term_gold = 5
				}
				# We're fine with them having 10 gold max
				
				if = {
					limit = {
						is_ai = no
					}
					every_held_title = {
						limit = {
							tier = tier_county
							title_province = {
								has_holding_type = herder_holding
							}
						}
						title_province = {
							set_holding_type = nomad_holding
						}
					}
					change_government = nomad_government
				}
			}
			# Make sure that Realm Priests are landed theocrats where it makes sense
			else_if = {
				limit = {
					highest_held_title_tier >= tier_duchy
				}
				if = {
					limit = {
						exists = cp:councillor_court_chaplain
						cp:councillor_court_chaplain = {
							is_ruler = no
						}
						faith = { has_doctrine = doctrine_clerical_succession_spiritual_fixed_appointment }
						any_vassal = {
							is_physically_able_adult = yes
							is_councillor = no
							government_has_flag = government_is_theocracy
							can_be_court_chaplain_trigger = { COURT_OWNER = liege }
							faith = liege.faith
						}
					}
					random_vassal = {
						limit = {
							is_physically_able_adult = yes
							is_councillor = no
							government_has_flag = government_is_theocracy
							can_be_court_chaplain_trigger = { COURT_OWNER = liege }
							faith = liege.faith
						}
						weight = {
							base = 1
							modifier = {
								add = 1000
								faith.religious_head ?= this
							}
							modifier = {
								add = learning
							}
							modifier = {
								add = primary_title.tier
							}
						}
						liege = {
							assign_councillor_type = {
								type = councillor_court_chaplain
								remove_existing_councillor = yes
								target = prev
							}
						}
					}
				}
				if = {
					limit = {
						is_landless_adventurer = yes
					}
					if = { limit = { has_realm_law = crown_authority_0 } remove_realm_law = crown_authority_0 }
				}
			}
			#Autopopulate families.
			if = {
				limit = {
					trigger_if = {
						limit = {
							has_game_rule = on_generate_families_ai_only
						}
						is_ai = yes
					}
					trigger_else = {
						has_game_rule = on_generate_families
					}
				}
				trigger_event = game_rule.1001
			}
		}

		if = {
			limit = {
				has_mpo_dlc_trigger = yes
			}
			#Fully Landlocked Nomad Cultures Setup
			every_culture_global = {
				limit = {
					OR = {
						has_cultural_pillar = heritage_mongolic
						has_cultural_pillar = heritage_ugro_permian
					}
				}
				add_to_global_variable_list = {
					name = fully_landlocked_nomad_cultures
					target = this
				}
			}
			add_to_global_variable_list = {
				name = fully_landlocked_nomad_cultures
				target = culture:kipchak
			}
			add_to_global_variable_list = {
				name = fully_landlocked_nomad_cultures
				target = culture:uyghur
			}
			add_to_global_variable_list = {
				name = fully_landlocked_nomad_cultures
				target = culture:kirghiz
			}
			add_to_global_variable_list = {
				name = fully_landlocked_nomad_cultures
				target = culture:tangut
			}
			add_to_global_variable_list = {
				name = fully_landlocked_nomad_cultures
				target = culture:bashkir
			}
			add_to_global_variable_list = {
				name = fully_landlocked_nomad_cultures
				target = culture:laktan
			}
			recalculate_cultural_heads_of_type = herd
		}

		### GAME RULE: VIEW ON SAME-SEX RELATIONS
		if = {
			limit = { has_game_rule = accepted_same_sex_relations }
			game_rule_accepted_same_sex_relations_effect = yes
		}

		### GAME RULE: RANDOM RULER PLACEMENT
		if = {
			limit = { NOT = { has_game_rule = random_ruler_placement_off } }
			game_rule_random_ruler_placement_effect = yes
		}

		### GAME RULE: RANDOMIZE FAITH
		if = {
			limit = { has_game_rule = randomized_faiths_on }
			game_rule_randomize_faith_effect = yes
		}

		### GAME RULE: FAITH ACCEPTANCE
		if = {
			limit = { has_game_rule = full_faith_acceptance }
			game_rule_faith_acceptance_effect = yes
		}

		### GAME RULE: GENDER EQUALITY ###
		if = {
			limit = { has_game_rule = full_gender_equality }
			game_rule_full_gender_equality_effect = yes
		}
		else_if = {
			limit = { has_game_rule = inversed_gender_equality }
			game_rule_inversed_gender_equality_effect = yes
		}

		### GAME RULE: SEXUALITY DISTRIBUTION ###
		if = {
			limit = { NOT = { has_game_rule = sexuality_distribution_default } }
			game_rule_sexuality_distribution_effect = yes
		}
		else = { # So that children 10+ starts with a sexuality
			child_sexuality_distribution_effect = yes
		}

		### GAME RULE: SITUATION TOGGLES
		struggle:iberian_struggle ?= {
			if = {
				limit = { has_game_rule = struggle_iberia_toggle_off }
				end_struggle = yes
			}
		}
		struggle:persian_struggle ?= {
			if = {
				limit = { has_game_rule = struggle_persia_toggle_off }
				end_struggle = yes
			}
		}
		situation:the_great_steppe ?= {
			if = {
				limit = { has_game_rule = situation_the_great_steppe_toggle_off }
				end_situation = yes
			}
		}

		### GAME RULE: RULER OF MUNSTER
		if = {
			limit = {
				game_start_date = 1066.9.15
				has_game_rule = historicity_ruler_of_munster_historical_toirdelbach
			}
			create_title_and_vassal_change = {
				type = conquest
				save_scope_as = title_change
			}
			character:83355 = {
				every_held_title = {
					limit = { tier >= tier_county }
					change_title_holder = {
						holder = character:906
						change = scope:title_change
					}
				}
				pay_short_term_gold = {
					target = character:83355
					gold = gold
				}
			}
			random_player = {
				limit = { this = character:83355 }
				set_player_character = character:906
			}
			resolve_title_and_vassal_change = scope:title_change
			# Since Murchad is back to his historical self, he gets to suck.
			character:83355 = {
				add_diplomacy_skill = -10
				remove_trait = gregarious
				add_trait = craven
				# Plus, usurpation rivalry — now Toidelbach has a perfectly good claim to the kingdom and will do a lot more with it than Murchad managed in his 5m in power, but by gameplay terms, this _is_ a usurpation.
				set_relation_rival = {
					target = character:906
					reason = rival_usurper
				}
			}
			# Alright, let's give Toirdelbach his alliance.
			character:906 = {
				add_opinion = {
					modifier = perk_negotiated_alliance_opinion
					target = character:922
				}
				reverse_add_opinion = {
					modifier = event_negotiated_alliance_opinion
					target = character:922
				}
				create_alliance = {
					target = character:922
					allied_through_owner = character:906
					allied_through_target = character:922
				}
			}
		}

		### GAME RULE: DETERMINISTIC CONQUEST
		if = {
			limit = {
				OR = {
					NOT = { has_game_rule = historicity_norman_conquest_default_random }
					game_rule_rig_norman_conquest_for_hereward_trigger = yes
				}
			}
			set_global_variable = deterministic_conquest_of_england_1066
			# See if we should just teleport our combatants' armies into place.
			trigger_event = {
				id = game_rule.1151
				trigger_on_next_date = 1066.09.25
			}
			trigger_event = {
				id = game_rule.1152
				trigger_on_next_date = 1066.10.14
			}
		}

		### 867 - MISC ###
		# Basileios has just murdered Michael III.
		character:1700 ?= { trigger_event = bookmark.0211 }

		### GAME RULE: EXTRA ADMINS
		## We'll be doing some excessive triggers below in a bid to lightly future-proof + error-spam mods less, don't worry about it.
		### We handle players after the lobby.
		# Historic chars.
		apply_historic_administrative_game_rule_effect = yes
		# Players.
		if = {
			limit = { has_dlc_feature = roads_to_power }
			if = {
				limit = {
					NOT = { has_game_rule = historicity_extra_admin_player_wherever_gameplay_not_administrative }
				}
				if = {
					limit = { has_game_rule = historicity_extra_admin_player_wherever_alt_historic_always }
					every_player = {
						limit = {
							highest_held_title_tier >= tier_kingdom
							NOR = {
								government_has_flag = government_is_administrative
								government_has_flag = government_is_landless_adventurer
							}
						}
						convert_to_administrative_from_feudalism_game_start_effect = yes
					}
				}
				else_if = {
					limit = { has_game_rule = historicity_extra_admin_player_wherever_alt_historic_with_august_trait }
					every_player = {
						limit = {
							highest_held_title_tier >= tier_kingdom
							NOR = {
								government_has_flag = government_is_administrative
								government_has_flag = government_is_landless_adventurer
							}
							has_trait = august
						}
						convert_to_administrative_from_feudalism_game_start_effect = yes
					}
				}
			}
		}

		# Give Ruler Designer characters regencies.
		every_in_global_list = {
			variable = rd_chars_needing_regencies
			trigger_event = diarchy.0011
			# Aaaand clean the list.
			save_temporary_scope_as = char_temp
			remove_list_global_variable = {
				name = rd_chars_needing_regencies
				target = scope:char_temp
			}
		}

		### ACHIEVEMENT: FROM RAGS TO RICHES
		every_player = {
			limit = { highest_held_title_tier = tier_county }
			add_achievement_global_variable_effect = {
				VARIABLE = achievement_rags_to_riches_valid
				VALUE = yes
			}
		}

		### ACHIEVEMENT (FP2): Holidaying in Iberia
		every_player = {
			limit = { fp2_character_involved_in_struggle_trigger = no }
			add_achievement_global_variable_effect = {
				VARIABLE = fp2_holiday_in_iberia_achievement_unlocked
				VALUE = no # Boolean in actual usage
			}
		}

		### ACHIEVEMENT TRACKING FOR STARTING CHARACTERS
		if = {
			limit = { has_multiple_players = no }
			every_player = {
				# Base Title
				if = {
					limit = {
						exists = character:7757
						this = character:7757
					}
					add_achievement_global_variable_effect = {
						VARIABLE = started_give_a_dog_a_bone_achievement
						VALUE = yes
					}
				}
				if = {
					limit = {
						exists = character:1128
						this = character:1128
					}
					add_achievement_global_variable_effect = {
						VARIABLE = started_wily_as_the_fox_achievement
						VALUE = yes
					}
				}
				if = {
					limit = {
						OR = {
							AND = {
								exists = character:108501
								this = character:108501
							}
							AND = {
								exists = character:107500
								this = character:107500
							}
							AND = {
								exists = character:107501
								this = character:107501
							}
							AND = {
								exists = character:108500
								this = character:108500
							}
							AND = {
								exists = character:109500
								this = character:109500
							}
						}
					}
					add_achievement_global_variable_effect = {
						VARIABLE = started_sibling_rivalry_achievement
						VALUE = yes
					}
				}
				if = {
					limit = {
						OR = {
							AND = {
								exists = character:163108
								this = character:163108
							}
							AND = {
								exists = character:163110
								this = character:163110
							}
							AND = {
								exists = character:163111
								this = character:163111
							}
							AND = {
								exists = character:163112
								this = character:163112
							}
							AND = {
								exists = character:163119
								this = character:163119
							}
						}
					}
					add_achievement_global_variable_effect = {
						VARIABLE = started_blood_eagle_achievement
						VALUE = yes
					}
				}
				if = {
					limit = {
						exists = character:6448
						this = character:6448
					}
					add_achievement_global_variable_effect = {
						VARIABLE = started_kings_to_the_seventh_generation_achievement
						VALUE = yes
					}
				}
				if = {
					limit = {
						exists = character:140
						this = character:140
					}
					add_achievement_global_variable_effect = {
						VARIABLE = started_norman_yoke_achievement
						VALUE = yes
					}
				}
				if = {
					limit = {
						exists = character:522
						this = character:522
					}
					add_achievement_global_variable_effect = {
						VARIABLE = started_royal_dignity_achievement
						VALUE = yes
					}
				}
				if = {
					limit = {
						exists = character:40605
						this = character:40605
					}
					add_achievement_global_variable_effect = {
						VARIABLE = started_land_of_the_rus_achievement
						VALUE = yes
					}
				}
				if = {
					limit = {
						exists = character:251187
						this = character:251187
					}
					add_achievement_global_variable_effect = {
						VARIABLE = started_mother_of_us_all_achievement
						VALUE = yes
					}
				}
				if = { # Temüjin
					limit = {
						has_mpo_dlc_trigger = yes
						exists = character:125501
						this = character:125501
					}
					add_achievement_global_variable_effect = {
						VARIABLE = started_the_stallion_that_mounts_the_world_achievement
						VALUE = yes
					}
				}
				if = {
					limit = {
						government_has_flag = government_is_nomadic
						save_temporary_scope_as = nomad_ruler
						situation:the_great_steppe ?= {
							situation_sub_region:steppe_east = {
								situation_sub_region_has_county = scope:nomad_ruler.capital_county
							}
						}
					}
					add_achievement_global_variable_effect = {
						VARIABLE = started_steppe_by_steppe_achievement
						VALUE = yes
					}
				}
				if = {
					limit = {
						OR = {
							culture = { has_cultural_pillar = heritage_iberian }
							culture = culture:andalusian
						}
						has_religion = religion:christianity_religion
					}
					add_achievement_global_variable_effect = {
						VARIABLE = started_reconquista_achievement
						VALUE = yes
					}
				}
				if = {
					limit = {
						culture = culture:irish
						capital_province = { geographical_region = custom_ireland }
					}
					add_achievement_global_variable_effect = {
						VARIABLE = started_the_emerald_isle_achievement
						VALUE = yes
					}
				}
				if = {
					limit = {
						OR = {
							culture = culture:castilian
							culture = culture:basque
							culture = culture:portuguese
							culture = culture:catalan
							culture = culture:andalusian
							culture = culture:visigothic
							culture = culture:suebi
						}
						has_religion = religion:islam_religion
						capital_province = { geographical_region = world_europe_west_iberia }
					}
					add_achievement_global_variable_effect = {
						VARIABLE = started_al_andalus_achievement
						VALUE = yes
					}
				}
				if = {
					limit = {
						exists = character:159137
						this = character:159137
					}
					add_achievement_global_variable_effect = {
						VARIABLE = started_almost_there_achievement
						VALUE = yes
					}
				}
				if = {
					limit = {
						exists = character:109607
						this = character:109607
					}
					add_achievement_global_variable_effect = {
						VARIABLE = started_last_count_first_king_achievement
						VALUE = yes
					}
				}
				if = {
					limit = {
						exists = character:6878
						this = character:6878
					}
					add_achievement_global_variable_effect = {
						VARIABLE = started_going_places_achievement
						VALUE = yes
					}
				}
				# FP1
				## far_from_home_achievement
				if = {
					limit = {
						# Starting as a Norse pagan Norse-cultured character.
						fp1_achievement_culture_plus_religion_norse_trigger = yes
					}
					add_achievement_global_variable_effect = {
						VARIABLE = started_far_from_home_achievement
						VALUE = yes
					}
				}
				## miklagardariki_achievement
				if = {
					limit = {
						# Starting as a Norse pagan Norse-cultured character.
						fp1_achievement_culture_plus_religion_norse_trigger = yes
					}
					add_achievement_global_variable_effect = {
						VARIABLE = started_miklagardariki_achievement
						VALUE = yes
					}
				}
				## canute_the_greater_achievement
				add_achievement_global_variable_effect = {
					VARIABLE = started_canute_the_greater_achievement
					VALUE = yes
				}
				## king_of_all_the_isles_achievement
				if = {
					limit = {
						# Starting as a Norse pagan Norse-cultured character.
						fp1_achievement_culture_plus_religion_norse_trigger = yes
					}
					add_achievement_global_variable_effect = {
						VARIABLE = started_king_of_all_the_isles_achievement
						VALUE = yes
					}
				}
				## faster_than_the_fox_achievement
				if = {
					limit = {
						# Starting as a Norse pagan Norse-cultured character.
						fp1_achievement_culture_plus_religion_norse_trigger = yes
					}
					add_achievement_global_variable_effect = {
						VARIABLE = started_faster_than_the_fox_achievement
						VALUE = yes
					}
				}
				## volva_achievement
				if = {
					limit = {
						# Starting as a Norse pagan Norse-cultured character.
						fp1_achievement_culture_plus_religion_norse_trigger = yes
					}
					add_achievement_global_variable_effect = {
						VARIABLE = started_volva_achievement
						VALUE = yes
					}
				}
				## saga_in_stone_achievement
				add_achievement_global_variable_effect = {
					VARIABLE = started_saga_in_stone_achievement
					VALUE = yes
				}
				## first_of_the_crusader_kings_achievement
				if = {
					limit = {
						# Starting as a Norse-cultured character.
						fp1_achievement_culture_norse_trigger = yes
					}
					add_achievement_global_variable_effect = {
						VARIABLE = started_first_of_the_crusader_kings_achievement
						VALUE = yes
					}
				}
				## vladimirs_second_choice_achievement
				if = {
					limit = {
						# Starting as a Norse pagan Norse or Rus-cultured character.
						fp1_achievement_culture_norse_or_rus_trigger = yes
						fp1_achievement_religious_norse_trigger = yes
					}
					add_achievement_global_variable_effect = {
						VARIABLE = started_vladimirs_second_choice_achievement
						VALUE = yes
					}
				}
				## a_dangerous_business_achievement
				add_achievement_global_variable_effect = {
					VARIABLE = started_a_dangerous_business_achievement
					VALUE = yes
				}
				# EP1
				##1 Patronage
				add_achievement_global_variable_effect = {
					VARIABLE = started_patronage_achievement
					VALUE = yes
				}
				##2 Converging Paths
				add_achievement_global_variable_effect = {
					VARIABLE = started_converging_paths_achievement
					VALUE = yes
				}
				##3 Changing course
				add_achievement_global_variable_effect = {
					VARIABLE = started_changing_course_achievement
					VALUE = yes
				}
				##4 Hoarder
				add_achievement_global_variable_effect = {
					VARIABLE = started_hoarder_achievement
					VALUE = yes
				}
				##5 creme de la creme
				add_achievement_global_variable_effect = {
					VARIABLE = started_creme_de_la_creme_achievement
					VALUE = yes
				}
				##6 Give it back!
				add_achievement_global_variable_effect = {
					VARIABLE = started_polyglot_achievement
					VALUE = yes
				}
				##7 Inspirational
				add_achievement_global_variable_effect = {
					VARIABLE = started_inspirational_achievement
					VALUE = yes
				}
				##8 One of a Kind
				add_achievement_global_variable_effect = {
					VARIABLE = started_one_of_a_kind_achievement
						VALUE = yes
				}
				##9 True Tolerance
				add_achievement_global_variable_effect = {
					VARIABLE = started_true_tolerance_achievement
					VALUE = yes
				}
				##10 Delusions of Grandeur
				add_achievement_global_variable_effect = {
					VARIABLE = started_delusions_of_grandeur_achievement_achievement
					VALUE = yes
				}
				##11 Bod Chen Po
				if = {
					limit = {
						this.dynasty = dynasty:105800
					}
					add_achievement_global_variable_effect = {
						VARIABLE = started_bod_chen_po_achievement
						VALUE = yes
					}
				}
				##12 Turkish Eagle
				if = {
					limit = {
						NOT = { this = character:3040 } # Not Alp Arslan
						house = house:house_seljuk # Seljuk
						game_start_date < 1067.1.1 # 1066 only, and no Seljuks in 867
					}
					add_achievement_global_variable_effect = {
						VARIABLE = started_turkish_eagle_achievement
						VALUE = yes
					}
				}
				##13 Rise of the Ghurids
				if = {
					limit = {
						has_title = title:d_ghur
						this.dynasty = dynasty:791 #Ghurid
					}
					add_achievement_global_variable_effect = {
						VARIABLE = started_rise_of_the_ghurids_achievement
						VALUE = yes
					}
				}
				##14 Brave and Bold
				if = {
					limit = {
						game_start_date < 868.1.1
						this.dynasty = dynasty:699 #Piast
					}
					add_achievement_global_variable_effect = {
						VARIABLE = started_brave_and_bold_achievement
						VALUE = yes
					}
				}
				##15 Lingua Franca
				add_achievement_global_variable_effect = {
					VARIABLE = started_lingua_franca_achievement
					VALUE = yes
				}
				##16 Beta Israel
				add_achievement_global_variable_effect = {
					VARIABLE = started_beta_israel_achievement
					VALUE = yes
				}
				## 17 They belong in a museum!
				add_achievement_global_variable_effect = {
					VARIABLE = started_they_belong_in_a_museum_achievement
					VALUE = yes
				}
				##18 I made this!
				add_achievement_global_variable_effect = {
					VARIABLE = started_i_made_this_achievement
					VALUE = yes
				}
				##19 Nobody Comes to Fika!
				add_achievement_global_variable_effect = {
					VARIABLE = started_nobody_comes_to_fika_achievement
					VALUE = yes
				}
				## 20 The True Royal Court
				add_achievement_global_variable_effect = {
					VARIABLE = started_the_true_royal_court_achievement
						VALUE = yes
				}
				# EP2
				## 01. The Grandest Tour
				add_achievement_global_variable_effect = {
					VARIABLE = started_the_grandest_tour_achievement
					VALUE = yes
				}
				## 02. Your Eternal Reward
				add_achievement_global_variable_effect = {
					VARIABLE = started_your_eternal_reward_achievement
					VALUE = yes
				}
				## 03. Imperial March
				add_achievement_global_variable_effect = {
					VARIABLE = started_imperial_march_achievement
					VALUE = yes
				}
				## 04. Black Dinner
				add_achievement_global_variable_effect = {
					VARIABLE = started_black_dinner_achievement
					VALUE = yes
				}
				## 05. There and Back Again
				add_achievement_global_variable_effect = {
					VARIABLE = started_there_and_back_again_achievement
					VALUE = yes
				}
				## 06. The Very Best
				add_achievement_global_variable_effect = {
					VARIABLE = started_the_very_best_achievement
					VALUE = yes
				}
				## 07. Like No One Ever Was
				add_achievement_global_variable_effect = {
					VARIABLE = started_like_no_one_ever_was_achievement
					VALUE = yes
				}
				## 08. A Thousand and One Night
				add_achievement_global_variable_effect = {
					VARIABLE = started_a_thousand_and_one_nights_achievement
					VALUE = yes
				}
				## 09. A Knight's Tale
				add_achievement_global_variable_effect = {
					VARIABLE = started_a_knights_tale_achievement
					VALUE = yes
				}
				## 10. Hunting Accident
				add_achievement_global_variable_effect = {
					VARIABLE = started_hunting_accident_achievement
					VALUE = yes
				}
				## 11. Lions and Tigers and Bears, Oh My!
				add_achievement_global_variable_effect = {
					VARIABLE = started_lions_and_tigers_and_bears_oh_my_achievement
					VALUE = yes
				}
				## 12. Fly, my Pretty!
				add_achievement_global_variable_effect = {
					VARIABLE = started_fly_my_pretty_achievement
					VALUE = yes
				}
				## 13. Pathway to Heaven
				add_achievement_global_variable_effect = {
					VARIABLE = started_pathway_to_heaven_achievement
					VALUE = yes
				}
				## 14. Sir Lance-a-Lot
				add_achievement_global_variable_effect = {
					VARIABLE = started_sir_lance_a_lot_achievement
					VALUE = yes
				}
				## 15. I'm in my Element(s)
				add_achievement_global_variable_effect = {
					VARIABLE = started_im_in_my_elements_achievement
					VALUE = yes
				}
				## 16. Ahab
				add_achievement_global_variable_effect = {
					VARIABLE = started_ahab_achievement
					VALUE = yes
				}
				## 17. Little William Marshal
				add_achievement_global_variable_effect = {
					VARIABLE = started_little_william_marshal_achievement
					VALUE = 0
				}
				add_achievement_global_variable_effect = {
					VARIABLE = little_william_marshal_achievement_tally
					VALUE = 0
				}
				## 18. A True & Perfect Knight
				add_achievement_global_variable_effect = {
					VARIABLE = started_a_true_and_perfect_knight_achievement
					VALUE = yes
				}
				## 19. A.E.I.O.U & Me
				if = {
					limit = {
						# Etichonen, of whom the Hapsburgs are a cadet - we check dynasty rather than house so that an accidental cadet doesn't screw you.
						this.house ?= house:house_habsburg
					}
					add_achievement_global_variable_effect = {
						VARIABLE = started_a_e_i_o_u_and_me_achievement
						VALUE = yes
					}
				}
				## 20. The Iron and Golden King
				add_achievement_global_variable_effect = {
					VARIABLE = started_the_iron_and_golden_king_achievement
					VALUE = yes
				}

				### RULER DESIGNER ACHIEVEMENT BLOCKS ###
				if = {
					limit = {
						num_virtuous_traits >= 3
					}
					add_achievement_flag_effect = { FLAG = rd_character_blocked_paragon_of_virtue_achievement_flag	}
				}
				if = {
					limit = {
						any_child = {
							count >= 10
							is_alive = yes
						}
					}
					add_achievement_flag_effect = { FLAG = rd_character_blocked_the_succession_is_safe_achievement_flag }
				}
				if = {
					limit = {
						any_child = {
							has_trait = inbred
						}
					}
					add_achievement_flag_effect = { FLAG = rd_character_blocked_keeping_it_in_the_family_achievement_flag }
				}
				if = {
					limit = {
						highest_held_title_tier >= tier_empire
						should_be_naked_trigger = yes
					}
					add_achievement_flag_effect = { FLAG = rd_character_blocked_the_emperors_new_clothes_achievement_flag }
				}
				if = {
					limit = {
						is_from_ruler_designer = yes
						OR = {
							fp1_achievement_culture_norse_trigger = yes
							fp1_achievement_religious_norse_trigger = yes
						}
					}
					add_to_global_unavailable_achievements_list_effect = { FLAG = flag:rd_character_blocked_far_from_home_achievement }
					add_to_global_unavailable_achievements_list_effect = { FLAG = flag:rd_character_blocked_miklagardariki_achievement }
					add_to_global_unavailable_achievements_list_effect = { FLAG = flag:rd_character_blocked_faster_than_the_fox_achievement }
				}
				if = {
					limit = {
						any_ruler = {
							is_from_ruler_designer = yes
						}
					}
					add_to_global_unavailable_achievements_list_effect = { FLAG = flag:rd_character_blocked_iberia_or_iberia_achievement }
					add_to_global_unavailable_achievements_list_effect = { FLAG = flag:rd_character_blocked_el_cid_achievement }
					add_achievement_global_variable_effect = {
						VARIABLE = any_ruler_designed_character_achievement
						VALUE = yes
					}
				}
				if = {
					limit = {
						has_mpo_dlc_trigger = yes
						exists = character:125501
						character:125501 = {
							is_alive = yes
						}
					}
					character:125501 = {
						create_story = story_temujin_flavor
						trigger_event = {
							days = { 12 30 }
							id = mpo_temujin_flavor.0030 # Borte announces she's pregnant
						}
					}
				}
			}
		}

		### ACHIEVEMENT (FP3): The Ummayad Strikes Back
		every_player = {
			if = {
				limit = {
					dynasty = character:73683.dynasty
					location = { geographical_region = world_europe_west_iberia }
				}
				set_global_variable = fp3_the_umma_strikes_back_achievement_tracker # Is not removed (sad!)
			}
		}

		### ACHIEVEMENT: FROM RAGS TO RICHES TO RAGS TO RICHES
		every_player = {
			limit = { highest_held_title_tier = tier_county }
			add_achievement_global_variable_effect = {
				VARIABLE = achievement_rags_to_riches_to_rags_to_riches_valid
				VALUE = yes
			}
		}

		#Set starting cultural acceptance
		culture:vlach = {
			change_cultural_acceptance = {
				target = culture:serbian
				value = 40
				desc = cultural_acceptance_historical_relations
			}
			change_cultural_acceptance = {
				target = culture:croatian
				value = 40
				desc = cultural_acceptance_historical_relations
			}
			change_cultural_acceptance = {
				target = culture:bosnian
				value = 40
				desc = cultural_acceptance_historical_relations
			}
			change_cultural_acceptance = {
				target = culture:bulgarian
				value = 40
				desc = cultural_acceptance_historical_relations
			}
		}
		culture:khazar = {
			change_cultural_acceptance = {
				target = culture:radhanite
				value = 25
				desc = cultural_acceptance_historical_relations
			}
			change_cultural_acceptance = {
				target = culture:mordvin
				value = 30
				desc = cultural_acceptance_historical_relations
			}
			change_cultural_acceptance = {
				target = culture:meshchera
				value = 30
				desc = cultural_acceptance_historical_relations
			}
			change_cultural_acceptance = {
				target = culture:muroma
				value = 30
				desc = cultural_acceptance_historical_relations
			}
			change_cultural_acceptance = {
				target = culture:russian
				value = 30
				desc = cultural_acceptance_historical_relations
			}
		}
		culture:norse = {
			change_cultural_acceptance = {
				target = culture:sami
				value = 20
				desc = cultural_acceptance_historical_relations
			}
			change_cultural_acceptance = {
				target = culture:finnish
				value = 20
				desc = cultural_acceptance_historical_relations
			}
		}
		culture:swedish = {
			change_cultural_acceptance = {
				target = culture:sami
				value = 20
				desc = cultural_acceptance_historical_relations
			}
			change_cultural_acceptance = {
				target = culture:finnish
				value = 20
				desc = cultural_acceptance_historical_relations
			}
		}
		culture:norwegian = {
			change_cultural_acceptance = {
				target = culture:sami
				value = 20
				desc = cultural_acceptance_historical_relations
			}
		}
		# In 867, the Slavic cultures are still very similar to each other, so we start them off at a very high tolerance.
		if = {
			limit = { current_date = 867.1.1 }
			# West Slavic.
			culture:pommeranian = {
				change_cultural_acceptance = {
					target = culture:czech
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:polish
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:polabian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:slovien
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:carantanian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:russian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:ilmenian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:severian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:volhynian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:croatian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:bosnian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:serbian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:bulgarian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
			}
			culture:czech = {
				change_cultural_acceptance = {
					target = culture:polish
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:polabian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:slovien
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:carantanian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:russian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:ilmenian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:severian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:volhynian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:croatian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:bosnian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:serbian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:bulgarian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
			}
			culture:polish = {
				change_cultural_acceptance = {
					target = culture:polabian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:slovien
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:carantanian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:russian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:ilmenian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:severian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:volhynian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:croatian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:bosnian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:serbian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:bulgarian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
			}
			culture:polabian = {
				change_cultural_acceptance = {
					target = culture:slovien
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:carantanian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:russian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:ilmenian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:severian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:volhynian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:croatian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:bosnian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:serbian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:bulgarian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
			}
			culture:slovien = {
				change_cultural_acceptance = {
					target = culture:carantanian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:russian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:ilmenian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:severian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:volhynian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:croatian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:bosnian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:serbian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:bulgarian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
			}
			culture:carantanian = {
				change_cultural_acceptance = {
					target = culture:russian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:ilmenian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:severian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:volhynian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:croatian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:bosnian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:serbian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:bulgarian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
			}
			# South Slavic.
			culture:croatian = {
				change_cultural_acceptance = {
					target = culture:russian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:ilmenian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:severian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:volhynian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:bosnian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:serbian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:bulgarian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
			}
			culture:bosnian = {
				change_cultural_acceptance = {
					target = culture:russian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:ilmenian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:severian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:volhynian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:serbian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:bulgarian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
			}
			culture:serbian = {
				change_cultural_acceptance = {
					target = culture:russian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:ilmenian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:severian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:volhynian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:bulgarian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
			}
			culture:bulgarian = {
				change_cultural_acceptance = {
					target = culture:russian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:ilmenian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:severian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:volhynian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
			}
			# East Slavic.
			culture:russian = {
				change_cultural_acceptance = {
					target = culture:ilmenian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:severian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:volhynian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
			}
			culture:ilmenian = {
				change_cultural_acceptance = {
					target = culture:severian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:volhynian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
			}
			## Volhynian doesn't get its own box, because we've already applied acceptance to it bilaterally everywhere else.
			#Splitting up Byzantine heritage means we need a little help reflecting historical relations
			culture:greek = {
				change_cultural_acceptance = {
					target = culture:armenian
					value = 20
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:georgian
					value = 20
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:alan
					value = 5
					desc = cultural_acceptance_historical_relations
				}
			}
		}
		if = {
			limit = {
				game_start_date >= 1066.1.1
				game_start_date < 1178.1.1
			}
			culture:greek = {
				change_cultural_acceptance = {
					target = culture:armenian
					value = 40
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:georgian
					value = 25
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:alan
					value = 10
					desc = cultural_acceptance_historical_relations
				}
			}
		}
		if = {
			limit = { game_start_date >= 1178.1.1 }
			culture:greek = {
				change_cultural_acceptance = {
					target = culture:armenian
					value = 30
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:georgian
					value = 15
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:alan
					value = 10
					desc = cultural_acceptance_historical_relations
				}
			}
		}


		# Specific innovation unlock
		if = {
			limit = {
				game_start_date >= 1066.1.1
			}
			every_culture_global = {
				limit = {
					OR = {
						has_cultural_pillar = heritage_arabic
						this = culture:yemeni
					}
				}
				add_innovation = innovation_ghilman
			}
		}
		# Custom ruler under the HRE should have lowered feudal obligations
		if = {
			limit = { exists = title:e_hre.holder }
			title:e_hre.holder ?= {
				every_vassal = {
					limit = {
						vassal_contract_has_modifiable_obligations = yes
					}
					vassal_contract_decrease_obligation_level = feudal_government_taxes
					vassal_contract_decrease_obligation_level = feudal_government_levies
					set_subject_contract_modification_blocked = no
				}
			}
		}
		### CE1 LEGITIMACY SETUP ###
		every_ruler = {
			limit = {
				has_legitimacy = yes
			}
			add_legitimacy = base_legitimacy_value
		}

		if = { # Special historical events for Matilda!
			limit = {
				character:7757 ?= { is_alive = yes }
			}
			character:7757 ?= {
				trigger_event = bookmark.1066 # Matildas marriage to her step-brother, with plausible historical options!
				trigger_event = { # Matildas suspected witchcraft, the player decides if its true or not!
					id = bookmark.1067
					years = { 1 5 }
				}
			}
		}

		if = { # Special historical events for Vratislav!
			limit = {
				character:522 ?= { is_alive = yes }
			}
			character:522 ?= {
				trigger_event = { # Vratislav and the Slavic Marches, he didn't historically get them (one briefly, but eh). The player chooses to appease the emperor or go after the coveted lands themselves!
					id = bookmark.1068
					days = { 35 120 }
				}
				trigger_event = { # Jaromir, Vratislav's brother, was a pain - this event is an opportunity for the player to handle the rivalry
					id = bookmark.1069
					days = { 1 29 }
				}
			}
		}

		if = { # Special historical events for Robert the Fox!
			limit = {
				character:1128 ?= { is_alive = yes }
			}
			character:1128 ?= {
				trigger_event = { # A Norman Sicily - Robert historically conquered quite a bit here, the player can choose how far they want to go and the risk they want to take. The more risk, the more event troops/claims.
					id = bookmark.1070
					days = { 35 120 }
				}
				trigger_event = { # The Pretender Monk - Raiktor is a historical character, a monk wo pretended to be a deposed Byzantine emperor which Robert used to beat up Byzantium. Here you can follow historical conquests (taking a bit of the coast) or go full on 'install him as emperor for real'-mode!
					id = bookmark.1071
					years = { 1 7 }
				}
			}
		}

		if = { # Special historical events for Emir Yahya!
			limit = {
				character:3924 ?= { is_alive = yes }
			}
			character:3924 ?= {
				trigger_event = { # Conquering Cordoba - Gain an opportunity to conquer Cordoba while gaining one of two buffs; one intrigue-focused, and one military. Historically he was poisoned after having conquered the city... but that's no fun for the player!
					id = bookmark.1072
					days = { 10 35 }
				}
			}
		}

		### EP3 SETUP ###
		if = {
			limit = { has_ep3_dlc_trigger = yes }
			### EP3 LAAMP SETUP ###
			# Resources.
			every_independent_ruler = {
				limit = { is_landless_adventurer = yes }
				# Cash.
				add_gold = {
					value = {
						value = 0
						add = prestige
						add = piety
						divide = 10
					}
				}
				save_temporary_scope_as = adventurer_scope
				# Set CoA
				primary_title = { set_coa = scope:adventurer_scope.house }
				# Cleanup characters
				every_councillor = {
					if = {
						limit = {
							NOR = {
								has_council_position = councillor_court_chaplain
								has_council_position = councillor_spouse
							}
						}
						scope:adventurer_scope = {
							fire_councillor = prev
						}
						remove_opinion = {
							modifier = fired_from_council_opinion
							target = scope:adventurer_scope
						}
					}
					else_if = {
						limit = {
							NOR = {
								is_close_or_extended_family_of = prev
								has_relation_lover = prev
								has_relation_friend = prev
								is_consort_of = prev
								has_council_position = councillor_spouse
							}
						}
						death = {
							death_reason = death_vanished
						}
					}
				}
				# Evict everyone who isn't your family from your camp.
				every_courtier = {
					limit = {
						prev = { save_temporary_scope_as = char_temp }
						NOR = {
							dynasty ?= scope:char_temp.dynasty
							is_imprisoned_by = scope:char_temp
							# Plus any relations, who are presumably meant to be here.
							has_important_relationship_with_character_trigger = { CHARACTER = scope:char_temp }
							# Catch bastards and such that may be left over.
							is_close_or_extended_family_of = scope:char_temp
						}
					}
					move_to_pool = yes
				}
				# Courtiers.
				trigger_event = ep3_laamps.1001
			}
			# Starting camp purposes.
			## Hereweard the Wake
			character:90028 ?= {
				if = {
					limit = { is_alive = yes }
					add_realm_law_skip_effects = camp_purpose_brigands
					if = {
						limit = {
							character:90160 = {
								NOT = { is_courtier_of = character:90028 }
							}
						}
						add_courtier = character:90160
					}
				}
				# Setup event for his story
				trigger_event = {
					id = ep3_laamps.5999
					days = { 1 2 }
				}
			}
			## El Cid
			character:107590 ?= {
				if = {
					limit = {
						is_alive = yes
						is_landless_adventurer = yes
					}
					add_realm_law_skip_effects = camp_purpose_mercenaries
					if = {
						limit = {
							character:71391 = {
								NOT = { is_courtier_of = character:107590 }
							}
						}
						add_courtier = character:71391
					}
					if = {
						limit = {
							character:castilian0248 = {
								NOT = { is_courtier_of = character:107590 }
							}
						}
						add_courtier = character:castilian0248
					}
					if = {
						limit = {
							character:castilian0249 = {
								NOT = { is_courtier_of = character:107590 }
							}
						}
						add_courtier = character:castilian0249
					}
				}
			}
			## Robert Crispin
			character:norman_crispin_06 ?= {
				if = {
					limit = {
						is_alive = yes
						is_landless_adventurer = yes
					}
					add_realm_law_skip_effects = camp_purpose_mercenaries
				}
			}
			## Hassan Sabbah
			character:41702 ?= {
				if = {
					limit = {
						is_alive = yes
						is_landless_adventurer = yes
					}
					add_realm_law_skip_effects = camp_purpose_scholars
				}
			}
			## Suleyman Qutalmishog
			character:3046 ?= {
				if = {
					limit = {
						is_alive = yes
						is_landless_adventurer = yes
					}
					add_realm_law_skip_effects = camp_purpose_mercenaries
					trigger_event = bookmark.1073 # Suleyman's beef with Alp Arslan
				}
			}
			## Wallada bint al-Mustakfi
			character:andalusian_0003 ?= {
				if = {
					limit = {
						is_alive = yes
						is_landless_adventurer = yes
					}
					add_realm_law_skip_effects = camp_purpose_scholars
					trigger_event = ep3_story_cycle_violet_poet.0001
				}
			}
			## Roger Raoul
			character:232504 ?= {
				if = {
					limit = {
						is_alive = yes
						is_landless_adventurer = yes
					}
					add_realm_law_skip_effects = camp_purpose_mercenaries
				}
			}
			## Taylu Danişmend
			character:danishmendid_1 ?= {
				if = {
					limit = {
						is_alive = yes
						is_landless_adventurer = yes
					}
					add_realm_law_skip_effects = camp_purpose_mercenaries
				}
			}
			every_independent_ruler = {
				if = {
					limit = { is_landless_adventurer = yes }
					# C... food.
					domicile = { change_provisions = starting_provisions_value }
					# Contracts
					if = {
						limit = { is_ai = no }
						# Set up additional firing contracts.
						player_adventurer_contract_generation_on_wait_in_place_effect = yes
						#generate contracts if you are far away from your previous location
						player_adventurer_contract_generation_on_domicile_moved_effect = yes
					}
					else = {
						create_story = { type = story_adventurer_ai }
						trigger_event = {
							on_action = on_adventurer_ai_new_employer_arrival
							days = { 10 30 }
						}
					}
					# Sort our starting flavourisation.
					if = {
						limit = { has_realm_law = camp_purpose_mercenaries }
						set_variable = flavourise_camp_purpose_mercenaries
					}
					else_if = {
						limit = { has_realm_law = camp_purpose_wanderers }
						set_variable = flavourise_camp_purpose_wanderers
					}
					else_if = {
						limit = { has_realm_law = camp_purpose_scholars }
						set_variable = flavourise_camp_purpose_scholars
					}
					else_if = {
						limit = { has_realm_law = camp_purpose_explorers }
						set_variable = flavourise_camp_purpose_explorers
					}
					else_if = {
						limit = { has_realm_law = camp_purpose_brigands }
						set_variable = flavourise_camp_purpose_brigands
					}
					else_if = {
						limit = { has_realm_law = camp_purpose_legitimists }
						set_variable = flavourise_camp_purpose_legitimists
					}
					# And tally our numbers for performance purposes.
					add_to_global_variable_list = {
						name = laamps_tally
						target = this.primary_title
					}
				}
				### EP3 ADMIN SETUP ###
				if = {
					limit = { government_allows = administrative }
					save_scope_as = top_liege
					### EP3 NOBLE FAMILIES & DOMICILE SETUP ###
					random_held_title = { # May be removed once every_noble_family includes liege (TIT-51212)
						limit = { is_noble_family_title = yes }
						set_coa = scope:top_liege.house
					}
					every_noble_family = {
						# Ensure Noble Family CoA match House
						set_coa = holder.house
						# Ensure holders of historical noble family titles are the default house heads
						holder ?= {
							save_scope_as = nf_holder
							if = {
								limit = { is_landed = yes }
								capital_province = { save_scope_as = domicile_location }
							}
							house ?= {
								if = {
									limit = { house_head != scope:nf_holder }
									set_house_head = scope:nf_holder
								}
							}
						}
						set_color_from_title = scope:nf_holder.capital_county
					}
				}
			}
		}
		# Byzantium naming
		title:e_byzantium = {
			if = {
				limit = {
					has_game_rule = eastern_rome_name_of_byzantium
				}
				set_title_name = e_eastern_roman_empire
			}
			else_if = {
				limit = {
					has_game_rule = roman_empire_name_of_byzantium
				}
				set_title_name = e_roman_empire
			}
			else_if = {
				limit = {
					has_game_rule = romania_name_of_byzantium
				}
				set_title_name = e_romania_empire
			}
			else_if = {
				limit = {
					has_game_rule = empire_of_the_greeks_name_of_byzantium
				}
				set_title_name = e_empire_of_the_greeks
			}
			else_if = {
				limit = {
					has_game_rule = rhomaion_name_of_byzantium
				}
				set_title_name = e_rhomaion
			}
			else_if = {
				limit = {
					has_game_rule = unholy_roman_empire_name_of_byzantium
				}
				set_title_name = e_unholy_roman_empire
			}
		}
		# Saharan stuff.
		every_county_in_region = {
			region = custom_sahara_proper
			# Every county is in the region, not every province of every county, so we go to county to avoid iterating over every world province _then_ check which ones are in the region.
			every_county_province = { apply_saharan_provisions_debuff_effect = yes }
		}
		# 1066 Buildings
		if = {
			limit = {
				shogunate_nanbokucho_period_start_date_trigger = yes
				shogunate_sengoku_period_start_date_trigger = no
			}
			every_province = {
				limit = {
					has_holding = yes
				}
				generate_building = yes
				brewery_counter_start_effect = yes
			}
			every_domicile = {
				if = {
					limit = {
						is_domicile_type = estate
						exists = owner
					}
					if = {
						limit = {
							NOT = { has_domicile_building_or_higher = estate_main_02 }
							owner.culture ?= { has_innovation = innovation_city_planning }
						}
						add_domicile_building = estate_main_02
						add_random_internal_estate_building = yes
					}

					fill_external_estate_building_effect = yes
				}
			}
		}
		# 1178 Buildings
		else_if = {
			limit = {
				shogunate_sengoku_period_start_date_trigger = yes
			}
			every_province = {
				limit = {
					has_holding = yes
				}
				generate_building = yes
#				generate_building = yes
#				generate_building = yes
#				generate_building = yes
#				generate_building = yes
#				generate_building = yes
				if = {
					limit = {
						county.development_level >= 50 # 8
					}
					generate_building = yes
#					generate_building = yes
				}
				if = {
					limit = {
						county.development_level >= 70 # 10
					}
					generate_building = yes
				}
#				if = {
#					limit = {
#						county.development_level >= 12
#					}
#					generate_building = yes
#				}
#				if = {
#					limit = {
#						county.development_level >= 14
#					}
#					generate_building = yes
#					generate_building = yes
#				}
#				if = {
#					limit = {
#						county.development_level >= 16
#					}
#					generate_building = yes
#				}
#				if = {
#					limit = {
#						county.development_level >= 18
#					}
#					generate_building = yes
#				}
#				if = {
#					limit = {
#						county.development_level >= 20
#					}
#					generate_building = yes
#				}
#				if = {
#					limit = {
#						county.development_level >= 25
#					}
#					generate_building = yes
#					generate_building = yes
#					generate_building = yes
#				}
				brewery_counter_start_effect = yes
			}
			every_domicile = {
				#if = { # Left in if we want adventurers to spawn with stuff
				#	limit = {
				#		is_domicile_type = camp
				#	}
				#	add_domicile_building = camp_main_02
				#	add_domicile_building = camp_main_03
				#	random_list = {
				#		10 = {
				#			add_domicile_building = supply_tent_01
				#			add_domicile_building = supply_tent_02
				#			random_list = {
				#				10 = {
				#					add_domicile_building = supply_tent_sutler
				#				}
				#				10 = {
				#					add_domicile_building = supply_tent_mender
				#				}
				#				10 = {
				#					add_domicile_building = supply_tent_smithy
				#				}
				#				10 = {
				#					add_domicile_building = supply_tent_arsenal
				#				}
				#			}
				#		}
				#		10 = {
				#			add_domicile_building = barber_tent_01
				#			add_domicile_building = barber_tent_02
				#			random_list = {
				#				10 = {
				#					add_domicile_building = barber_tent_surgeons_tools
				#				}
				#				10 = {
				#					add_domicile_building = barber_tent_dentists_tools
				#				}
				#				10 = {
				#					add_domicile_building = barber_tent_torturers_tools
				#				}
				#			}
				#		}
				#		10 = {
				#			add_domicile_building = baggage_train_01
				#			add_domicile_building = baggage_train_02
				#			random_list = {
				#				10 = {
				#					add_domicile_building = baggage_train_ample_steeds
				#				}
				#				10 = {
				#					add_domicile_building = baggage_train_porters
				#				}
				#				10 = {
				#					add_domicile_building = baggage_train_trackers
				#				}
				#				10 = {
				#					add_domicile_building = baggage_train_kennel
				#				}
				#			}
				#		}
				#	}
				#	random_list = {
				#		10 = {
				#			add_domicile_building = mess_tent_01
				#			add_domicile_building = mess_tent_02
				#			random_list = {
				#				10 = {
				#					add_domicile_building = mess_tent_herbalists
				#				}
				#				10 = {
				#					add_domicile_building = mess_tent_brewers
				#				}
				#				10 = {
				#					add_domicile_building = mess_tent_curers
				#				}
				#				10 = {
				#					add_domicile_building = mess_tent_bakers
				#				}
				#				10 = {
				#					add_domicile_building = mess_tent_cooks
				#				}
				#			}
				#		}
				#		10 = {
				#			add_domicile_building = camp_fire_01
				#			add_domicile_building = camp_fire_02
				#			random_list = {
				#				10 = {
				#					add_domicile_building = camp_fire_trailing_musicians
				#				}
				#				10 = {
				#					add_domicile_building = camp_fire_wandering_poets
				#				}
				#				10 = {
				#					add_domicile_building = camp_fire_capering_fools
				#				}
				#				10 = {
				#					add_domicile_building = camp_fire_libations_for_the_lost
				#				}
				#			}
				#		}
				#	}
				#	random_list = {
				#		10 = {
				#			add_domicile_building = camp_perimeter_01
				#			add_domicile_building = camp_perimeter_02
				#			random_list = {
				#				10 = {
				#					add_domicile_building = camp_perimeter_good_siting
				#				}
				#				10 = {
				#					add_domicile_building = camp_perimeter_fixed_layout
				#				}
				#			}
				#		}
				#		10 = {
				#			add_domicile_building = proving_grounds_01
				#			add_domicile_building = proving_grounds_02
				#		}
				#	}
				#}
				if = {
					limit = {
						is_domicile_type = estate
						exists = owner
					}
					if = {
						limit = {
							NOT = { has_domicile_building_or_higher = estate_main_02 }
							owner.culture ?= { has_innovation = innovation_city_planning }
						}
						add_domicile_building = estate_main_02
						add_random_internal_estate_building = yes
					}
					if = {
						limit = {
							has_domicile_building = estate_main_02
							NOT = { has_domicile_building_or_higher = estate_main_03 }
							owner.culture ?= { has_innovation = innovation_manorialism }
						}
						add_domicile_building = estate_main_03
						while = {
							count = 2
							add_random_internal_estate_building = yes
						}
					}

					fill_external_estate_building_effect = yes
				}
			}
		}
		# Purge family titles if Admin isn't enabled
		if = {
			limit = {
				NOT = { has_dlc_feature = roads_to_power }
			}
			every_ruler = {
				save_temporary_scope_as = this_ruler
				every_held_title = {
					limit = {
						has_title_law = noble_family_succession_law
					}
					scope:this_ruler = {
						destroy_title = prev
					}
				}
			}
		}

		every_county_in_region = {
			region = world_steppe
			limit = {
				uses_county_fertility = yes
			}

			if = {
				limit = {
					holder = {
						government_has_flag = government_is_nomadic
					}
					county_fertility > 20
					county_fertility <= 90
				}
				switch = {
					trigger = holder.primary_title.tier
					tier_empire = {
						change_county_fertility = { 16 32 }
					}
					tier_kingdom = {
						change_county_fertility = { 12 16 }
					}
					tier_duchy = {
						change_county_fertility = { 8 12 }
					}
					tier_county = {
						change_county_fertility = { 2 8 }
					}
				}
			}
			else_if = {
				limit = {
					holder = {
						government_has_flag = government_is_herder
					}
				}
				change_county_fertility = { 44 64 }
 			}
		}

		# Conquerors
		character:144133 ?= {
			if = {
				limit = {
					is_alive = yes
					NOT = { has_game_rule = no_conquerors_frequency }
				}
				create_story = story_conqueror
			}
		}
		character:144141 ?= {
			if = {
				limit = {
					is_alive = yes
					NOT = { has_game_rule = no_conquerors_frequency }
				}
				create_story = story_conqueror
			}
		}
		character:175080 ?= {
			if = {
				limit = {
					is_alive = yes
					NOT = { has_game_rule = no_conquerors_frequency }
				}
				create_story = story_conqueror
			}
		}
		character:226000 ?= {
			if = {
				limit = {
					is_alive = yes
					NOT = { has_game_rule = no_conquerors_frequency }
				}
				create_story = story_conqueror
			}
		}
		
		every_player = {
			limit = {
				is_landed = yes
			}
			while = {
				count = 7
				limit = {
					any_courtier = {
						count < 7
						is_adult = yes
					}
				}
				save_scope_as = player_scope
				random_list = {
					1 = {
						create_character = {
							employer = scope:player_scope
							age = { 20 30 }
							random_traits = yes
							gender_female_chance = scope:player_scope.marriage_gender_adjusted_female_chance
							culture = scope:player_scope.culture
							faith = scope:player_scope.faith
							after_creation = {
								random_list = {
									200 = {
										# Character is of average weight, nothing happens	
									}
									25 = {
										change_current_weight = -25
									}
									25 = {
										change_current_weight = -75
									}
									25 = {
										change_current_weight = 25
									}
									25 = {
										change_current_weight = 75
									}
									5 = {
										change_current_weight = 150
									}
								}
							}
						}
					}
					4 = {
						create_character = {
							employer = scope:player_scope
							age = { 20 40 }
							random_traits = yes
							gender_female_chance = 15
							culture = scope:player_scope.culture
							faith = scope:player_scope.faith
							after_creation = {
								random_list = {
									200 = {
										# Character is of average weight, nothing happens	
									}
									25 = {
										change_current_weight = -25
									}
									25 = {
										change_current_weight = -75
									}
									25 = {
										change_current_weight = 25
									}
									25 = {
										change_current_weight = 75
									}
									5 = {
										change_current_weight = 150
									}
								}
							}
						}
					}
				}
			}
		}

		# Sanity check the setup if in debug mode
		if = {
        	limit = {
        		debug_only = yes
        	}
	        run_setup_tests_effect = yes
    	}
		set_global_variable = game_has_started
	}

	events = {
		game_rule.1011	#Hungarian Migration management.
		historical_artifacts.0023			# Historical Artifacts Generator

		# Shogunate
		shogunate_startup.0002		# Setup Living Characters
		shogunate_bookmark.0002		# Setup Historical Situation
		shogunate_building.0001		# Setup Building Controllers
		shogunate_kamon.0002		# Setup Kamon CoA
	}
}

#$CHARACTER$.house = {
#			save_scope_as = character_house
#
#			add_unity_value = {
#				value = {
#					value = $VALUE$
#					if = { # House heads have a larger impact on unity
#						limit = { house_head = $CHARACTER$ }
#						multiply = unity_house_head_multiplier_value
#					}
#				}
#				character = $CHARACTER$
#				desc = $DESC$
#			}
#		}

